delay before NeXT scene

I have code which starts the scene again when player touhces an enemy. But I want little delay before it reloads the scene I have tried ali but noting Works same Time would be good if game Pauses all timers and an other variables and this all should happen in ontriggerenter function pl z help

Best practice is to use a Coroutine. Here’s an example of how you might code one just to test out the delay:

using System.Collections;
using UnityEngine;

public class Test : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(MyCoroutine(3));
    }

    IEnumerator MyCoroutine(float delayTime)
    {
        yield return new WaitForSeconds(delayTime);
        //Add your Scene Restart code here
    }
}

thanks iam now in School but ill try it later
:slight_smile:

@SurreyMuso I tested it but it is not working. Am i doing smothing wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class kuolee : MonoBehaviour
{
     
    public float delayTime = 3;

    IEnumerator MyCoroutine(float delayTime)
     {
         yield return new WaitForSeconds(delayTime);
         SceneManager.LoadScene("Level2");
     }
    private void OnTriggerEnter2D(Collider2D collision)
     {
        if(collision.tag == "Player")
        {
            
            StartCoroutine(MyCoroutine(3));
        }
     }
}