Answers for "how to use a singleton controller unity"

C#
4

how to make a singleton in unity

void Awake()
 {
   if (instance == null)
     instance = this;
   else if (instance != this)
     Destroy(gameObject);
 }
Posted by: Guest on November-03-2020
0

how to create a singleton in unity

public class SomeClass : MonoBehaviour {
    private static SomeClass _instance;

    public static SomeClass Instance { get { return _instance; } }


    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        } else {
            _instance = this;
          	DontDestroyOnLoad(gameObject);
        }
    }
}
Posted by: Guest on December-29-2021

Code answers related to "how to use a singleton controller unity"

C# Answers by Framework

Browse Popular Code Answers by Language