Time for action – creating the level selection
A new scene and a single script will serve us well in managing our level selection:
- This last section begins by saving your current scene and hitting Ctrl + N to create a new one, named
LevelSelect
. - For this scene, we need to create a single, short script also named
LevelSelect
. - The first and only variable defines the size of the buttons that will appear on screen.
public int buttonSize = 100;
- The only function is the
OnGUI
function. This function starts with a loop. It will loop through three times for the three levels we should have created earlier. ARect
variable is created and initialized to thebuttonSize
. The x and y values are then set to position the buttons in a row, centered on the screen. Next, the current high score for the level is retrieved, usingPlayerPrefs.GetInt
and the same key creation that we used in ourLevelTracker
script. Then, the function creates a string to hold the message that will appear on the button. Finally...