Debug Collision and Next Level Solution

Hi, this is my solution. I’ll see what Rick did now.

One thing I’m not sure about is if it is good practice to do this in a separate script altogether, such as a Debug Script.

public class CollisionHandler : MonoBehaviour
{
    [SerializeField] float loadLevelDelay = 2f;
    [SerializeField] AudioClip spaceShipCrash;
    [SerializeField] AudioClip successClip;
    [SerializeField] bool isDebug = true;

    [SerializeField] ParticleSystem spaceShipCrashParticlesFX;
    [SerializeField] ParticleSystem successParticlesFX;

    AudioSource audioSource;

    bool isTransitioning = false;
    bool isCollision = true;

    Movement movement;

    private void Start()
    {
        audioSource = GetComponent<AudioSource>();
    }

    private void Update()
    {
        if (isDebug)
        {
            if (Input.GetKey(KeyCode.C)) 
            { 
                isCollision = !isCollision;
                Debug.Log("Colliosion is, " + isCollision);
            }
            if (Input.GetKey(KeyCode.L)) 
            { 
                LoadnextLevel();
                Debug.Log("Next Level");
            }
        }
    }

    private void OnCollisionEnter(Collision collision)
    {
        if (!isTransitioning && isCollision)
        {
            switch (collision.gameObject.tag)
            {
                case "Friendly":
                    break;
                case "Fuel":
                    break;
                case "Finish":
                    SuccessSequence();
                    break;
                case "Ball":
                    break;
                default:
                    CrashSequence();
                    break;
            }
        }
    }

Hey, sorry for digging up this old question; I’ve replied to another thread here because I was wondering about the same thing …

In short, I have no idea what the best practices are (would love it if more experienced gamedevs could chime in), but how I currently saw it:

  • Separate script is good to keep everything together
    • just disabling the script, and all debug/cheating is disabled
    • this one file lists all “cheat codes”
  • Separate script is bad because you have to expose stuff
    • maybe you have properties that are only needed inside a component (i.e., it’s a private variable)
    • if an external script needs to modify these, you have to make it public … But then all others can also access such variables (which I guess feels like bad practice, publicly exposing methods if they are not meant to be publicly exposed)
    • also the argument that “all keys are together”, I’m not sure if that’s really necessary … Even “regular input” can be spread over multiple scripts (e.g., WASD in my Movement script, Spacebar and mousescroll in my Weapons script), so I don’t think it’s such a bad thing if debug keys also get spread out over their appropriate scripts

Still, I’d love to hear what others have to say about this :slight_smile:

Privacy & Terms