I’m doing a little project and I want to make a target respawn some seconds after dies. I’m using a coroutine but nothing happens after the ‘yield return new WaitForSeconds(3);’
I am calling it with StartCoroutine() and I don’t recieve any errors, it just doesn’t work. I do see the ‘Boop’ on the console but I don’t see the ‘BOOPBOOPBOOP’
using UnityEngine;
using System.Collections;
public class bulletdetect : MonoBehaviour {
private float Health = 10f;
void OnTriggerEnter (Collider col) {
if (col.CompareTag ("Bullet")) {
Health -= 2;
}
}
void Update() {
if (Health <= 0f) {
Health = 10f;
Destroy (gameObject);
StartCoroutine ("respawn");
}
}
IEnumerator respawn() {
Debug.Log ("Boop"); yield return new WaitForSeconds (3f);
Debug.Log ("BOOPBOOPBOOP");
Instantiate (gameObject);
}
}