Gameplay loops

Well done so far. You have added basic functionality such as jumping, physics, and running to the PlayerController object. We are definitely going in the right direction here. The next important step is writing a neat GameManager class to help us control the game events, such as:

  • StartGame
  • GameOver
  • Restart

For basic games such as Jake on the mysterious planet, it is a good practice to have one instance of the GameManager running and controlling all main events in the game. The gameplay loop is simply a journey from the gameplay start to the gameplay phase and the game over phase. Time to write some code!

Let's create a new C# script and call it GameManager, and write the following code:

As you can see, nothing is very complicated. ...

Get Learning C# 7 By Developing Games with Unity 2017 - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.