"God Mode" & Level skipper

My ‘no collision’ code, i thought M was a bit easier considering the controller layout I have… still need to refactor a little

if (!Input.GetKey(KeyCode.M))
        {
            switch (collision.gameObject.tag)
            {

                case "Safe":
                    //print("Safe");
                    // Do nothing, safe is safe.
                    break;
                case "Finish":
                    // User moves to next level
                    // TODO - finish needs to only be allowed when ship is upright...
                    startFinishSequence();
                    break;
                default:
                    startDyingSequence();
                    break;

            }
        }

and my level code… I also made an update to allow the player to play sequentially through the levels (i had to dig through Unity docs a little to figure it out.



...
    Scene scene;
    enum State { Alive, Dying, Transcending };
    int sceneCount;
    State state = State.Alive;

    // Start is called before the first frame update
    void Start()
    {
        scene = SceneManager.GetActiveScene(); // Get current scene details
        sceneCount = SceneManager.sceneCountInBuildSettings; // Get total number of scenes in game
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
    }

    private void ReloadLevel()
    {
        // TODO allow for more than 2 levels
        SceneManager.LoadScene(scene.buildIndex);
    }

    private void LoadNextLevel()
    {
        // TODO only load the current scene that you died on
        // if it's not the last scene, then load the next scene...
        if (scene.buildIndex < sceneCount-1)
        {
            SceneManager.LoadScene(scene.buildIndex + 1);
        }

    }


    // DEBUG TOOLS
    private void skipLevel()
    {
        if (Input.GetKey(KeyCode.L))
        {
            LoadNextLevel();
        }
    }

mahblahblah,

I really like how you load your levels. I also do something similar using number of levels but it is way messier. Thank you for showing your code!

GK :slight_smile:

Thank you!

Privacy & Terms