Setting up your Scenes

You should now have a project panel with seven folders and a scene with Main Camera and OuyaGameObject that you have entered your developer ID into. We are going to use this scene as a setup scene that isn't displayed for long but instead adds all the required game objects. Normally in Unity, when loading a new scene, all objects are destroyed, and then the objects in the new scene are loaded. If it is needed to have an object persist between scenes then there is a method, DontDestroyOnLoad that you can pass an object to. If the object is a component or GameObject then its entire transform hierarchy will not be destroyed either. A side effect of this is that if the scene has the GameObject added to it in Unity and you load it multiple times (on a level select screen for example) then the GameObject will be cloned multiple times and, with a GameObject that handles controller input for example, this can result in multiple controller presses being triggered. We can avoid this by having all our GameObjects that require DontDestroyOnLoad being instantiated on a scene that we will only ever load the one time.

As we won't be displaying anything on this scene, you should delete Main Camera. We'll also need a mechanism to leave this scene and load the next one, by performing the following steps:

  1. Save the current scene as SetUp by clicking on File | Save Scene, and select the Scenes folder you created earlier.
  2. While we're dealing with scenes, let's create another one we're going to be using shortly. Click on File | New Scene, and select the Scenes folder you created earlier. Give it a name of TitleScreen and click on Save.
  3. Repeat these steps to create a scene named GameScreen too. This will have left us in the wrong scene, so double-click on our SetUp scene again to load that one.
  4. Your final setup should look like the following screenshot:
    Setting up your Scenes
..................Content has been hidden....................

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