LAZY INSTANTIATION
OBJECTIVE: Create a GameManager Script to allow for Lazy Instantiation if the instance of the GameManager returns NULL
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-15 --> 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
_instance
is null, a new game object is created within the hierarchy and the GameManager script is attached.==> LAZY INSTANTIATION <==
THIRD: If not NULL the property returns the instance of itself, allowing the other script access
LINE 18-21 --> Initialized the singleton while the program initially loads
This is where the program assigns _instance to this script
Last updated