Game Development Reference
In-Depth Information
{
if(nextStateTime > 0.0f)
{
if(nextStateTime < Time.time)
{
// Set the button back to its 'up' state
nextStateTime = 0.0f;
upSprite.SetActive(true);
downSprite.SetActive(false);
currentState = StartButtonController.buttonStates.up;
// Start the game!
stateManager.startGame();
}
}
}
}
Now that you've added StartButtonController to the start button, populate its
various fields and you can try it out! Now when you start the game, it will launch on
the title screen, and when you click on the START! button, it will go to the gameplay
we have seen this whole time.
Once you play the game, you will probably notice the one final thing we need
to clean up. The player is able to move on the title screen. Let's use that global
if(!GameStates.gameActive) Boolean field to fix that.
Let's fix the player movement first. Open PlayerStateController , and at the
beginning of LateUpdate() , add the following code:
if(!GameStates.gameActive)
return;
Now the game won't accept any input unless it is actually active. Other ways to
accomplish this include setting the timescale of the engine to 0 when the game isn't
running, or only generating the player and enemies after the game starts. Also, if you
haven't done so already, remove the enemy from the center platform. We don't need
him to be on top of the player as soon as the game starts!
Pro tip
Using sprites or 3D models for our GUIs gives us the added benefit of
having animated elements. Try your hand at making the buttons scale,
the UI slide in and out of the screen, and in general, just have fun with
Unity's animation tool to create awesome GUI animations!
 
Search WWH ::




Custom Search