void OnDestroy() { m_referenceCount--; if (m_referenceCount == 0) { m_instance = null; } }
void Awake() { m_referenceCount++; if (m_referenceCount > 1) { DestroyImmediate(this.gameObject); return; } m_instance = this; // Use this line if you need the object to persist across scenes //DontDestroyOnLoad(this.gameObject); }