IEnumerator OnHit() { anim.SetTrigger("Die"); GameControllerScript.PedestrianKilled(); isAlive = false; if (allowPedestrianWarning) { audio.PlayRandomFromList(0, true); allowPedestrianWarning = false; yield return(new WaitUntil(() => audio.finishedQueue)); allowPedestrianWarning = true; } Destroy(this.gameObject, 30); }
// Start is called before the first frame update void Start() { game = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameControllerScript>(); rend = GetComponentInChildren <Renderer>(); if (type == PoliceType.Regular) { regPoliceList.AddLast(this); } game.allPoliceList.Add(this); rbody = GetComponent <Rigidbody>(); col = GetComponent <Collider>(); play = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerScript>(); agent = GetComponent <NavMeshAgent>(); targetPos = play.transform.position; audio = GetComponent <AudioTriggerScript>(); RandomizeXOffset(); InvokeRepeating("SlowUpdate", 0f, 0.1f); if (playAudio) { audio.PlayRandomFromList(0, true); } if (type == PoliceType.Regular) { Invoke("ShootBullet", Random.Range(shootFrequencyMin, shootFrequencyMax)); } if (type == PoliceType.Rammer) { Invoke("StartRam", Random.Range(ramTimeFrequencyMin, ramTimeFrequencyMax)); } if (type == PoliceType.Tanker) { Invoke("StartMissiles", Random.Range(missileFrequencyMin, missileFrequencyMax)); game.myMissileAnim = transform.Find("missile").GetComponent <Animation>(); game.myMissileParticle = game.myMissileAnim.transform.GetComponentInChildren <ParticleSystem>(); game.generateObstacles = false; } }