private void Start() { intersectionStatistics = new IntersectionStatistics(); //adds user choosen lightcontroller GameObject intersection = this.gameObject; if (PlayerPrefs.GetString("light") == "TimedLightController") { intersection.AddComponent <TimedLightController>(); } lightController = GetComponent <iLightController>(); if (null == lightController) { Debug.LogError(transform.name + " has no lightcontroller"); Destroy(this); }//Gets light controller or errors }
private bool cleared = true;//Tracks whether an intersection was cleared after end of last light private void Awake() { //this.gameObject.AddComponent<IntersectionStatistics>() intersectionStatistics = this.gameObject.AddComponent <IntersectionStatistics>(); //adds user choosen lightcontroller or use existing if (true == PlayerPrefs.HasKey("light") && 0 == this.gameObject.GetComponents <iLightController>().Length) { switch (PlayerPrefs.GetString("light")) { case "TimedLightController": lightController = (iLightController)this.gameObject.AddComponent(typeof(TimedLightController)); break; case "RandomLightController": lightController = (iLightController)this.gameObject.AddComponent(typeof(RandomLightController)); break; case "GreedyLightController": lightController = (iLightController)this.gameObject.AddComponent(typeof(GreedyLightController)); break; default: lightController = GetComponent <iLightController>(); break; } } else { lightController = GetComponent <iLightController>(); } if (null == lightController) { Debug.LogError(transform.name + " has no lightcontroller"); Destroy(this); }//Gets light controller or errors }