SINGLETON DECLARATION
OBJECTIVE: Create a GameManager Class with the use of the Singleton Design Pattern
When you declare a singleton class, you are telling that class that you are going to have a reference among all classes --> The entire program will know that this class exists --> There will never be a duplicate of this class
CODE BREAKDOWN
LINE 3 --> Creates a private static instance of the current class
_instance
is going to define the instance of THIS GameManager and there never can be more than ONE instance of a single class
LINE 4 --> Creates a public static instance of this class
Needed for script communication
Needs to be a property that other classes GET but cannot SET
LINE 6-12 --> Defines the GET property for the Instance property
when another script calls upon the Instance property the following happens...
FIRST: program checks that _instance is not NULL (I.E. that the class exists within the hierarchy)
SECOND: If not NULL the property returns the instance of itself, allowing the other script access
LINE 15-18 --> Initialized the singleton while the program initially loads
This is where the program assigns _instance to this script
Last updated