Unity In-Game Title Screen

Hal Brooks
3 min readOct 9, 2021

Objective: Create a title screen, allowing the player to start or restart.

Title menu with start button to begin game.

Add a UI > Text object to the Canvas called Title_text, and add a title for the game increasing the font size and changing the color, see below.

Title_text setup.

Now add the Start_Button by selecting UI > Button. Adjust the colors, size and position as desired. The button has a child text object, and set the display text to “Start Game” with a font size of 20. The UIManager.StartGame method in On Click() is what allows the button to function. Drag the Canvas onto the added On Click() to give access the UIManager.

Start_button setup.

The UIManager on the Canvas sets a number of variables required to control the UI interface and communicates the game state with GameManager script. Below are the required variables in the UIManager script. The _player is assigned in void Awake, which occurs before void Start.

Variable required for User Interface (UI)

Many of these variables are assigned in the inspector, shown below. References to the _keyCards[] game objects and their _toggles[] and their Panel. A reference to the Title_text, the Start_Button and its Text child of the button are also required.

Variable assignment in Canvas Inspector window.

The GameManager has a few new variables as well. In addition to tracking HasCards, it tracks if the GameRunning and if the player dies, i.e. GameOver.

GameManager singleton.

The UI Manager needs the StartGame() method shown below, which is called when the player presses the start button. The UI interface text objects are disabled and card state is rest, via ToggleCard() method. The game manager is told that the game is running and not over. The _player.ActivatePlayer() method is called. The panel is activated and button and GraphicRaycaster disabled.

StartGame method in UIManager on Canvas.

The ToggleCard method on the UIManager is shown below, and resets the key card state for the _toggles[] and HasCards[] in the GameManager.

ToggleCard method on UIManager.

The Player gameObject initially has SetActive false in the void Start method, but after the UIManager has a reference to the Player in void Awake(). The ActivatePlayer script on Player sets the position of the player to the initial position, sets the _yVelocity to zero and stes the Player to an active state.

ActivatePlayer method in Player script.

The player can now begin the game if they dare.

Key learning is that an in-game UI system requires extensive communication with the game. Carefully consider using a separate scene for the title page in combination with the Unity SceneManagement to load the game scene.

--

--