private void FindAllInstances() { var currentInstances = SGT_Helper.FindAll <T>(); staticInit = true; instances = new System.Collections.Generic.HashSet <T>(currentInstances); }
public void Awake() { var instances = SGT_Helper.FindAll <T>(); if (instances.Length > 1) { Debug.LogWarning("An instance of " + typeof(T).Name + " already exists!"); Debug.Log("Removing other " + (instances.Length - 1) + " instance(s) of " + typeof(T).Name); // Destroy other instances foreach (var i in instances) { if (i != this) { SGT_Helper.DestroyObject(i); } } } instance = (T)this; }