October 2017
Intermediate to advanced
548 pages
13h 23m
English
We've written one controller for the app, PictureController, which manages a picture. We could add a CreateNewPicture function there, but what if the scene is empty and there is no PictureController? What component function gets called to add a new picture to the scene? Let's create a separate GameController to support creating new pictures.
There should only be one GameController in our scene, so we make it a singleton. The singleton pattern ensures there will never be more than one instance of a class. In Unity and C#, we can implement singletons. In your Scripts folder, create a new C# script and name it GameController:
File: GameControllerusing UnityEngine; public class GameController : MonoBehaviour { public static GameController ...Read now
Unlock full access