0
votes

public class Gamemanager : MonoBehaviour {

public static Gamemanager instance; [SerializeField] private void Awake(){

if(instance == null) // if instance is not initilized then instance is equal to class
  instance =this;

}

}//classs

1
This is an implementation of the singleton pattern. en.wikipedia.org/wiki/Singleton_patternLeo Bartkus

1 Answers

0
votes

Basically we want to make sure that the static (!) "instance" variable will always hold the reference to the same instance of the Gamemanager no matter what, even if for some reason, multiple instances of Gamemanager are created. As it has been mentioned above, this is also called "Singleton pattern".