public void MyAwake() { if (Trump == null) { Trump = this; } else { DestroyImmediate(Trump); } }
void Awake() { #region SINGLETON if (instance == null) { instance = this; } else { Destroy(gameObject); } #endregion UIBehaviours = new List <IBehaviour>(); Behaviours = new List <IBehaviour>(); // Add UI Behaviours UIBehaviours.Add(mapUI as IBehaviour); // Cria todos os behaviours GameObject virusObj = CreateObj("VirusBehaviour"); virusBehaviour = virusObj.AddComponent <VirusBehaviour>(); virusBehaviour.virusPopperPrefab = VirusPopperPrefab; virusBehaviour._VirusUI = virusUI; GameObject mapObj = CreateObj("MapBehaviour"); mapBehaviour = mapObj.AddComponent <MapBehaviour>(); mapBehaviour.RegionPrefab = RegionPrefab; mapBehaviour.WGrid = 41; mapBehaviour.HGrid = 27; mapBehaviour.SeaLevel = 0.4f; mapBehaviour.Scale = 0.2f; mapBehaviour.transform.position = new Vector3(-8.881f, -5f); GameObject wallObj = CreateObj("TrumpBehaviour"); trumpBehaviour = wallObj.AddComponent <TrumpBehaviour>(); trumpBehaviour.WallPrefab = WallPrefab; AddBehaviour(mapBehaviour as IBehaviour); AddBehaviour(virusBehaviour as IBehaviour); AddBehaviour(trumpBehaviour as IBehaviour); GameObject timerManager = CreateObj("TimerManager"); timer = timerManager.AddComponent <Timer>(); timeUI.timer = timer; // Run Logic Behaviours first foreach (IBehaviour behaviour in Behaviours) { behaviour.MyAwake(); } foreach (IBehaviour behaviour in Behaviours) { behaviour.MyStart(); } // Run UI Behaviours second foreach (IBehaviour behaviour in UIBehaviours) { behaviour.MyAwake(); } foreach (IBehaviour behaviour in UIBehaviours) { behaviour.MyStart(); } }