Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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);
        }
    }
}
Source by www.studica.com #
 
PREVIOUS NEXT
Tagged: #create #singleton #unity
ADD COMMENT
Topic
Name
4+8 =