![]() ![]() Using UnityEngine.SceneManagement has been added as we will be switching scenes to the game scene.Īpplication.Quit() will quite the game when not run in the Unity editor. This will house all the code for our buttons. You should end up with something like this:įull Unity 2D Game Tutorial 2019 – Responding to Button EventsĪdd a new component to the MainMenu object and create a new c# script called MainMenuController. Rename all your buttons and button texts so we have a start button and options button and an exit button. Do this twice to create a total of 3 buttons. Select the StartButton in the hierarchy window and using the ctrl+d shortcut to duplicate it. We have finished creating the style for the button, so now we duplicate it and make another 2. To apply this gradient to your text you will have to check the Color Gradient box and drop the gradient you made into the colour preset box. I went with a fire orange > red like the image below. Adjust the colours to something you like. Create a folder called TMPResources and right click Create > TextMeshPro > Color Gradient and name it MenuGradient. We’re going to fix that by using a colour gradient for TextMeshPro. The button looks better but the text is still rather boring. Pure black for normal, a tint of blue for highlighted and a dark grey for pressed all set with 80 alpha.įull Unity 2D Game Tutorial 2019 – TextMeshPro Text Style The image below shows how I have set mine. Let’s fix that by adjusting the button colours. We should now have a big ugly white box in the center of our screen. The TextMeshPro text doesn’t automatically fill the start button size, it actually is larger than the button by default so use the Anchor presets again to fit the button with the same Shift+Alt clicking the bottom right icon we did before. Set the text to Start and change the size to say 64. The original text element isn’t as good as the TextMeshPro text so delete the current text and replace it with a TextMeshPro text. The size of our canvas and main menu have been set but our button hasn’t. We set the Child Alignment to Upper Center so all our buttons will be laid out in the middle of our screen starting from the top. This will layout our objects for us and keep things displaying neatly in a vertical line. On the MainMenu object add a new component called Vertical Layout Group. Use the Anchor Presets to fill the entire canvas with the MainMenu by Shift+Alt clicking the bottom right icon. The MainMenu object at the moment is just a small square area inside the canvas. Full Unity 2D Game Tutorial 2019 – Menu Style Move the StartButton inside the Main Menu object. The reason we do this is so we can swap between menus by deactivating the main menu and showing the options menu and vice versa. ![]() This will be the object that holds all our main menu UI. We need more order, so add an empty game object to the canvas and name it Main Menu. ![]() We have our button but its just there floating around inside the canvas. ![]() The Canvas is done for now so lets setup the main menu. This is a small 16:9 aspect ratio and should allow us to work on a multitude of displays without too many issues. First set the UI Scale Mode to Scale With Screen Size. Now we have a canvas let’s set it up so it work’s on multiple display sizes. This will not only create the button but also the Canvas and Event System. The first thing we are going to do is to add a button. Full Unity 2D Game Tutorial 2019 – Menu UI We now have music and a background in our main menu. Open the new Main Menu scene and paste the objects. Now save your GameScene and select the background and AudioManager objects in the hierarchy view and right click > copy. While were here right click and add a new scene and name it MainMenu. Let’s fix that by right clicking on the scene in the project window and renaming it to GameScene. We have our game scene but its just called SampleScene. In this part of the tutorial we will be crating the main menu and adding some buttons to allows us to play a game, go to the options menu and to exit the game. Full Unity 2D Game Tutorial 2019 – Main Menu ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |