[Solved]Can't get Death delay to work

So I’m stumped and after an hour of trying to bug fix, i think its time to get help. Ok so i got my laser defender scene loop working. I start up, hit the start button, fight, die, go to game over and start the loop all over again. However when I did the challenge I set up my code like this

 private void Die()
    {
        SceneManager.LoadScene("GameOver");
        Destroy(gameObject);
        AudioSource.PlayClipAtPoint(deathSound, Camera.main.transform.position, deathSoundVolume);
    }
`

However after I watched the way you guys did it, I replicated it, and I can’t get it to work like that. I keep getting NullReferenceExceptions and my ship wont die.

private void Die()
    {

        FindObjectOfType<Level>().LoadGameOver();
        Destroy(gameObject);
        AudioSource.PlayClipAtPoint(deathSound, Camera.main.transform.position, deathSoundVolume);
    }

I broke down and straight up copied your Level.cs script and re set up all my buttons and stuff. Just for some reason the “FindObjectOfType().LoadGameOver();” is breaking it. If i comment it out everything works as expected. I’m really at a loss of what I did wrong.

Edit

I stepped away, ate some lunch, watched some videos and revisited the problem an hour later. Turns out I broke the Level prefab at some point. My gameover, and my start were fine the problem only found itself onto my actual game scene.

Edit

I stepped away, ate some lunch, watched some videos and revisited the problem an hour later. Turns out I broke the Level prefab at some point. My gameover, and my start were fine the problem only found itself onto my actual game scene.

Adding the solution to a reply means we can make it as a solution :slight_smile: I appreciate trying to keep it tidy by editing your post though :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms