My crush delay does not work as intended

Hello, so I’ve went ahead and noticed that my crush delay does not work as intended, it does not actually delays. My finish line works just fine but it seems like my crush is not, I serialized it and it does not change at all, there is no delay, thank you.

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

public class CrashDetector : MonoBehaviour
{
    
    [SerializeField] ParticleSystem crashEffect;
    [SerializeField] AudioClip wilhelmScream;
    [SerializeField] float crushDelay = 0.5f;
    void OnTriggerEnter2D(Collider2D other) 
    
     
    {
        if(other.tag == "Ground")
        {
            crashEffect.Play();
            GetComponent<AudioSource>().PlayOneShot(wilhelmScream);
            Invoke("ReloadScene", crushDelay);
           SceneManager.LoadScene(0);
        }
        
    }
     void ReloadScene()
     {
         SceneManager.LoadScene(0);
     }

    
}

Hi Gladius,

Invoke does not pause the OnTriggerEnter2D. This means the entire code block gets executed within milliseconds. Take another look at your code block to see if that’s really the code that is supposed to get executed.

Ah, I see, I’m not sure where I’ve gone wrong though, its really the same as the the video tutorial, so im not entirely sure what’s supposed to get executed.
thanks for the help.

@gladius, I’m sorry for the late reply. For some reason, I missed your answer. How are you getting on with this problem?

Privacy & Terms