Hello there! It’s me with my seemingly endless Unity problems. This time, I want to create a WaitForSecond function inside an OnCollisionEnter function. So naturally I changed it into IEnumerator. But the WaitForSecond still doesn’t occur. What seems to be the problem here?
void Start() {
//StartCoroutine("OnCollisionEnter", ????);
}
IEnumerator OnCollisionEnter (Collision coll) {
if(coll.gameObject.tag == "bullet")
{
hitPoints -= bulletDamage;
}
if (hitPoints <= 0 && enemy == true)
{
Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy(gameObject); // YES, the object destroyed.
yield return new WaitForSeconds(1); // NO, it didn't wait.
Time.timeScale = 0; // NO, this didn't happen also.
info.text = "YOU WIN!"; //NO.
}
}
As you can see I’ve also tried to call the function with StartCoroutine but I can’t figure out what parameter should I put into the bracket. Sounds noobish? I am one. Any kinds of help appreciated!