GameController

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 ...

Get Augmented Reality for Developers 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.