Reload Current Level Upon Death

Some feedback I got was it was frustrating to get all the way to level 5 and then die, resulting in going back to level 1. Of course some people will enjoy that challenge but others may just give up and never complete the game. So with that being said I made a few changes to the code and created a new method

First under StartDeathSequence() change the Invoke string to “LoadCurrentLevel”

private void StartDeathSequence()
    {
        //Ded
        state = State.Dying;
        audioSource.Stop(); // stops thrusting sound before death sound
        audioSource.PlayOneShot(death);
        deathParticles.Play();
        Invoke("LoadCurrentLevel", levelLoadDelay);
        print("DED");
        // kill the player
    }

Then create a new method for LoadCurrentLevel and use the following Scene Manager code

private void loadCurrentLevel()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }

I hope this helps anyone wanting to reload the current level :slight_smile:

1 Like

Thank you so much for making this!

Privacy & Terms