Be the first to post for 'Debug Keys & Builds'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.

I approached my collider debugging slightly differently, I guess in a more “no clipping” way by actually disabling the colliders:

    if (Input.GetKeyDown (KeyCode.C))
    {
        foreach (Collider rocketCollider in rocketColliders)
        {
            rocketCollider.enabled = !rocketCollider.enabled;
        }
    }

It’s not as clean as Ben’s implementation but it does have the added benefit of being able to plough through the scenery and take the most direct route anywhere!

I also added a ResetGame ( ) as part of an earlier video so I could easily test Level_01 when I had the Level_03 scene loaded in Unity. Resetting the game is one of the first things I add when making a game for how handy it is!

else if (Input.GetKeyDown (KeyCode.R))
{
ResetGame ();
}

private void ResetGame ()
{
    SceneManager.LoadScene (0);
}
2 Likes

Greetings Everyone!

So I’ve been developing other features as we continue on the course. I’m keeping the actual variables in a gameObject that does not destroy itself on loading the next level. In that way I can keep some info from scene to scene. I used developerModeOn bool and disableCollisionsOn bool on this object so it could be persistent through scene changes. The idea of putting in the L and C keys struck home with me so I went ahead and added a few more useful controls:

Project SkyEye Developer Controls:

Ctrl-Alt-M		Management(Developer Mode) toggle.

	Inside Developer Mode:
	
	C 			Collisions disabled toggle.
	F			Fuel use toggle.
	G			Game restart.
	L			Level reload.
	N			Next level.
	X			Explode rocket.

The following is my code from my developer method:

   private void CheckDeveloperMode()
    {
        // Use Ctrl-Alt-M for management or Developer mode.
        if (Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.M))
        {
            // Toggle developer mode.
            statsKeeper.SetDeveloperModeOn(!statsKeeper.GetDeveloperModeOn());
        }

        if (statsKeeper.GetDeveloperModeOn())
        {
            if (Input.GetKeyDown(KeyCode.C)) // Toggle disableCollisionsOn.
            {
                statsKeeper.SetDisableCollisionsOn(!statsKeeper.GetDisableCollisionsOn());
            }
            else if (Input.GetKeyDown(KeyCode.F)) // Toggle Fuel Use.
            {
                statsKeeper.SetDisableFuelUseOn(!statsKeeper.GetDisableFuelUseOn());
            }
            else if (Input.GetKeyDown(KeyCode.G)) // Restart Game.
            {
                StartNewGame();
            }
            else if (Input.GetKeyDown(KeyCode.L)) // Reload the level.
            {
                SceneManager.LoadScene(curLevel);
            }
            else if (Input.GetKeyDown(KeyCode.N)) // Next Level
            {
                LoadNextScene();
            }
            else if (Input.GetKeyDown(KeyCode.X)) // Explode Rocket.
            {
                DieingSequence();
            }
        }

The use of the Debug.isDebugBuild is very handy and I can see myself using that in a project I plan on releasing. For now, I think I will leave it out as it would be fun to play with those controls. This project has grown quite a bit larger than I had intended, but I will say I’m having fun doing it. :slight_smile:

Jenn

3 Likes

I made two new functions:

    void LevelCheat() 
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            LoadNextLevel();
        }
    }

    void CollisionCheat()
    {
        if (Input.GetKeyDown(KeyCode.C))
        {
            noCollision = !noCollision;

            if (noCollision)
            {
                print("no Collision");
            } else 
            {
                print ("yes collisions");
            }
        }
    }

I then call the two cheat functions within Update(). Which then affects the death sequence:

    private void StartDeathSequence()
    {
        if (noCollision)
        {
            return;
        }
        state = State.Dying;
        audioSource.Stop();
        audioSource.PlayOneShot(death);
        deathParticles.Play();
        Invoke("LoadFirstLevel", loadLevelDelay);
    }

Works well. It turns off the bad collisions, but leaves the success sequence running. And of course I added Ben’s “toggle” and isDebugBuild into it. :slight_smile:

@JennBren

I see you have gone down the fuel use path… would you care to share your implementation?

What gameObject do you have that isn’t destroyed on level loads/scene changes.

I love how it has a sign at the bottom right stating that it is a Dev Build.

Nice to now about this feature.

1 Like

Hi all, this is my solution.

I started with an “enum” first, as such:

enum DebugMode { Advance, CollisionON, CollisionOFF}
DebugMode mode = DebugMode.CollisionON;

Then:

// Update is called once per frame
void Update()
{
    if (state == State.Alive)
    {
        RespondToThrustInput();
        RespondToRotateInput();
    }
    // todo
    DebugModeOnOff();
}

I used “switch” method to change the state of my enum “mode”:

private void DebugModeOnOff()
{

    if (Input.GetKey(KeyCode.L))
    {
        LoadNextLevel();
    }
    else if (Input.GetKey(KeyCode.C))
    {
        //turn on or off the collision detection
        switch (mode)
        {
            case DebugMode.CollisionON:
                mode = DebugMode.CollisionOFF;
                break;

            default:
                mode = DebugMode.CollisionON;
                break;
        }
    }
    else { return; }
}

Then last but not least, I made sure to ignore the death sequence from starting as such:

void OnCollisionEnter(Collision collision)
{
    if (state != State.Alive) { return; }
    
    switch (collision.gameObject.tag)
    {
        case "Friendly":
            // Do nothing
            break;

        case "Finish":
            StartSuccessSequence();
            break;

        default:
            // check if the collision detection is ON or OFF
            if (mode != DebugMode.CollisionON) { return; }
            StartDeathSequence();
            break;
    }
}

Is this okay? I would love some feedback. Criticism is highly appreciated… constructive criticism that is :smiley:

P.s. I realize I have not set up DebugMode.Advance yet; I left that out for something I might need in the future.

Privacy & Terms