Respawn issues

Hello there. I’ve got some troubles with my respawn script. I’ve read a lot about respawning scripts but haven’t found what would be the best for my video game :<
I think that almost everything is ok in this script, except when i use “Debug.Log(“message”);”, I figure out that this part of the script is not executed. Could someone help me ? Thanks !

public float maxHealth = 1000f;
public float curHealth = 0f;
private bool isAlive = true;
private float timer;
private int waitingTime = 2;
public GameObject enemyPrefab;
private GameObject spawnPos;
private StatsMage statsMage;

void Start () {
    curHealth = maxHealth;
    statsMage = Character.GetComponent<StatsMage>();
    enemyPrefab = GameObject.Find("ennemy");
    spawnPos = GameObject.Find("spawnPos");

}
void OnCollisionEnter(Collision col)
{
    if (col.gameObject.tag == "Weapon")
    {
        curHealth -= statsMage.DamageDealMage;
    }
}
void Update () {
        if (curHealth <= 0)
        {
            isAlive = false;
            Destroy(enemyPrefab);
        }
        if (isAlive == false)
        {
            timer += Time.deltaTime;
            if (timer > waitingTime)
            {

                Debug.Log("Message");
                Instantiate(enemyPrefab,spawnPos.transform);
                isAlive = true;
                timer = 0;
            }
        }
    }

hi;
in this situations u better Debug the “if” statement values for example “Timer” or “isAlive” and see if they are doing fine or not cause i don’t see any problem in your script;

Thanks for your answer mate !

I debugged the if statement values. isAlive = false, and timer is equal to 0.0152… so I think my timer is kind of broken.

I tried with a StartCoroutine, same problem.

IEnumerator respawn8()
{
    Debug.Log("isAlive = " + isAlive);
    yield return new WaitForSeconds(2);
    isAlive = true;
    Debug.Log("isAlive = " + isAlive);
    Instantiate(enemyPrefab, spawnPos.transform);
}
    void Update () {
        if (curHealth <= 0)
        {
            isAlive = false;
            Destroy(enemyPrefab);
        }
        if (isAlive == false)
        {
            StartCoroutine(respawn8());
            Debug.Log("isAlive = " + isAlive);
        }
    }

The Debug.Log under StarCoroutine is OK, the first Debug.Log in the respawn8 is OK, but I think that he doesn’t want to execute “yield return new WaitForSeconds(2);”, I don’t know why