Use UNITY_EDITOR scripting symbol for hiding it from published build

For anyone wondering about a better way for hiding these cheat codes so the Internet people don’t abuse your game :slight_smile:

You can use UNITY_EDITOR scripting symbol (Unity - Manual: Conditional Compilation) .

Like this:

#if UNITY_EDITOR
    private bool debugCollisionDisabled;
#endif
    private void Update() {
#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.C)) {
            debugCollisionDisabled = !debugCollisionDisabled;
        }
#endif
    }
    private void OnCollisionEnter(UnityEngine.Collision collision) {
#if UNITY_EDITOR
        if (debugCollisionDisabled) {
            return;
        }
#endif
        ... (rest of the code) ...
        }

Privacy & Terms