Setting up input keys

One more thing that's missing now is adding s into Unity's build in InputManager. To do that, follow these simple steps.

  1. Open InputManager by going to Edit | ProjectSettings | Input.
  2. Increase input size of Axis by 1.
  3. Select the bottom Axis and change its settings.
    Setting up input keys

We have a new input button set up as well as the code executed each time the button is pressed. Time to test that. Press Play in Unity and, after Jake drops on the platform, press S on the keyboard. The StartGame() method will be called by Unity just after you pressed the key. The StartGame() method changes currentGameState to inGame so our gameplay starts.

So, we completed the first part of the simple gameplay loop. The user can start the game by pressing the button and the game will start. As we are calling it a loop, it will have to be a closed chain of events. To close the gameplay, we will need to add the GameOver event.

In our simple game, the game over event will be called when the player dies. There will be two ways to kill the player:

  • By falling through the hole in the ground
  • By hitting obstacles

We already have the physics functionality working, which means Jake is falling through the holes. All we need to do is create some sort of trigger telling GameManager, "Player fallen through the hole, game over!"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset