IEnumerator Start () { target = gameObject.GetComponentInParent<PoliceCarController>(); while (true) { if( !target.patrolMode) { GetComponent<Light>().enabled = !(GetComponent<Light>().enabled); //toggle on/off the enabled property gameObject.GetComponent<Light>().color=Color.blue; } else { gameObject.GetComponent<Light>().color = Color.white; GetComponent<Light>().enabled = true; //toggle on/off the enabled property } yield return new WaitForSeconds(flickeringFreq); } }
// Use this for initialization void Start() { target = GetComponent<PoliceCarController>(); sirenClip = GetComponent<AudioSource>(); }