Time for action - adding a Player GameObject

  1. Add Player to Scene0. We also need to make changes to Scene1 and Scene2.
  2. Click on GameManager and make sure its Transform Position is 0,0,0.
  3. Add Player to Scene0.
  4. Set the Transform Position for Player to 0,1,0.
  5. Make Player a child object of the GameManager by dragging Player onto GameManager. Why?
    • Player needs to be able to exist in every Scene
    • Since GameManager is already allowed to exist in all Scenes as a result of the DontDestroyOnLoad() method called in StateManager, any child objects of GameManager will also be allowed to exist in all Scenes
  6. I suggest adding Directional Light to Scene0 so everything added to the Scene isn't dark.
  7. Make it a child of GameManager as well so that all Scene instances will have light.
  8. Save Scene0 and load Scene1.
  9. Remove any GameObjects in the Scene.
  10. Save Scene1 and load Scene2.
  11. Remove any GameObjects in the Scene.
  12. Finally, reload Scene0 since this is the starting Scene.

What just happened?

When you click on Play and move from one Scene to another, you will see the Player appear in every Scene, along with the Directional Light.

Storing game data in its own script

The whole purpose of the State Machine is its simplicity of control. However, a game's code needs to access many types of data. For instance, we're going to show three splash screens. Do we really want to fill the State Machine itself with all kinds of variables storing image files and other game data? How about scoring data? Of course not, otherwise the script starts getting long and cumbersome to read.

Instead, let's create a separate Component script class whose sole purpose is to contain game data. This way we know exactly where to look for the data when we need it, and where to store it during the game. All we'll need to do is create a single variable in the StateManager that points to (references) this special data script.

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

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