My toggle collisions method

… is not as neat as Ben’s…

...
int collisions = 0;
...
private void RespondToDebugKeys()
    {
        if (Input.GetKey(KeyCode.L))
        {
            // Load next level
            Invoke("LoadNextLevel", 0f);
        }

        if (Input.GetKey(KeyCode.C))
        {
            // toggle collision detection

            if (collisions == 1)
            {
                collisions = 0;
            }
            else
            {
                collisions = 1;
            }
        }
    }

void OnCollisionEnter(Collision collision)
    {
        if (state != State.Alive) { return; }  // stop registering collisions when dead
        if (collisions == 1) { return; }
...

Privacy & Terms