I have a problem with this script that gives me errors. My project consists of respawn the player and the prefab enemies after being destroyed after 5 seconds in the same original position but the script gives me a lot of errors and I don't know how to fix them. can you give me some help to correct the script? Thanks
using UnityEngine;
using System.Collections;
public class respawn : MonoBehaviour {
void OnCollisionEnter(Collision collision) {
StartCoroutine(Respawn(5f, 5f));
}
IENumerator Respawn(float timeToDespawn, float timeToRespawn) {
yield return new WaitForSeconds(timeToDespawn);
gameObject.SetActive(false);
yield return new WaitForSeconds(5f);
gameObject.SetActive(true);
}
CodePudding user response:
You spelled IEnumerator
wrong. The N
needs to be lowercase. Consider using an IDE. That would have detected your mistake and would also give you huge lot of help developing. I suggest either Microsoft VisualStudio or Jetbrains Rider
CodePudding user response:
I fix my error tanks but the prefab don't respawn. what I'm looking for is a script that regenerates the destroyed-dead prefabs after a few seconds. Can this problem be solved? I've been going crazy for 2 days. Can you please correct the script.? thank you.