How do i delay a Scenes Loading?

Hey,
I need to delay Scenes loading for about three seconds

my code:

private AudioSource audioSource;
public AudioClip DeathSoundEffect;
void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.tag == "Player")
    {
        audioSource = GetComponent<AudioSource>();
        audioSource.clip = DeathSoundEffect;
        audioSource.Play();
       //The delay commaned here
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}

I’v tried

other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
if (count >= 15)

did’nt work it miss all of the Script

Try using asynchronous scene loading like this to wait until the scene is loaded and the arbitrary timer is done:


private AudioSource audioSource;
public AudioClip DeathSoundEffect;
public float timeToWait = 3.0f;

private void OnCollisionEnter2D(Collision2D other)
{
    if (other.gameObject.tag == "Player")
    {
        audioSource = GetComponent<AudioSource>();
        audioSource.clip = DeathSoundEffect;
        audioSource.Play();

        StartCoroutine(LoadAsyncScene(SceneManager.GetActiveScene().name);
    }
}

IEnumerator LoadAsyncScene(string sceneName) 
{
    AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
    
    // Stop scene from activating
    asyncOperation.allowSceneActivation = false;
    
    // Wait until scene fully loads 
    while (!asyncLoad.isDone) 
    { 
        yield return null; 
    } 
    
    yield return new WaitForSeconds(timeToWait);
    
    asyncOperation.allowSceneActivation = true;
    Debug.Log("Scene Loaded");
}