Debug mode cannot be switched off

Hi,

I am wondering why my debug keys are still working (C & L) even though I already switched off the development build setting as shown in the video?

Thanks

Here is the code I made.


// IMPORTANT NOTES FOR THIS SCRIPT !
// ***************** Putting particles on the rocket and the game *****************
//
// Putting particle on the rocket, when death and finish

using System;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Rocket : MonoBehaviour
{

    [SerializeField] float rcsThrust = 100f; // The value can be different from the editor or inspector under Rocket (Script)
    [SerializeField] float mainThrust = 100f; // The value can be different from the editor or inspector under Rocket (Script)
    [SerializeField] float levelLoadDelay = 2f;

    [SerializeField] AudioClip mainEngine;
    [SerializeField] AudioClip success;
    [SerializeField] AudioClip death;

    [SerializeField] ParticleSystem mainEngineParticles;
    [SerializeField] ParticleSystem successParticles;
    [SerializeField] ParticleSystem deathParticles;


    Rigidbody rigidBody;
    AudioSource audioSource;

    enum State { Alive, Dying, Transcending }
    State state = State.Alive;
    bool collisionsDisabled = false;


        // Use this for initialization
    void Start()
        {
            rigidBody = GetComponent<Rigidbody>();
            audioSource = GetComponent<AudioSource>();   
        }

        // Update is called once per frame
        void Update()
        {
            // to do somewhere stop sound on death
            if (state == State.Alive)
            {
                RespondToThrustInput();
                RespondToRotateInput();
            }

            // todo only if debug on
            if (Debug.isDebugBuild)
            {
                RespondToDebugKeys();
            }
            
        }

    private void RespondToDebugKeys()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            LoadNextLevel();
        }
        else if (Input.GetKeyDown(KeyCode.C))
        {
            collisionsDisabled = !collisionsDisabled; // toggle
        }
    }

    void OnCollisionEnter (Collision collision)
        {
            if (state != State.Alive || collisionsDisabled) {return;} // ignore collision when death. Don't execute the following switch code for collision
                                                // return = get out of the function
            switch (collision.gameObject.tag)
            {
                case "Friendly":
                    // do nothing
                    print("Starting point"); // to do remove this
                    break;
                case "Finish":
                    StartSuccessSequence();
                    break;
                default:
                    StartDeathSequence();
                    break;
            }
        }

    private void StartSuccessSequence()
    {
        state = State.Transcending;
        audioSource.Stop();
        audioSource.PlayOneShot(success);
        successParticles.Play();
        Invoke("LoadNextLevel", levelLoadDelay); // parameterise time
    }

    private void StartDeathSequence()
    {
        state = State.Dying;
        audioSource.Stop();
        audioSource.PlayOneShot(death);
        deathParticles.Play();
        Invoke("LoadFirstLevel", levelLoadDelay); // parameterise time
    }


    private void LoadNextLevel()
        {
            SceneManager.LoadScene(1); // to do allow for more than 2 levels
        }

        private void LoadFirstLevel()
        {
            SceneManager.LoadScene(0);
        }

        private void RespondToThrustInput()
        {

            if (Input.GetKey(KeyCode.Space)) // can thrust while rotating
        {
            ApplyThrust();
        }
        else
            {
                audioSource.Stop();
                mainEngineParticles.Stop();
            }
        }

        private void ApplyThrust()
        {
            rigidBody.AddRelativeForce(Vector3.up * mainThrust);
            if (!audioSource.isPlaying) // to reduce sound of  'bmmbmbb'. If not playing, then play the sound
            {
                audioSource.PlayOneShot(mainEngine);
            }
            mainEngineParticles.Play();
        }

        private void RespondToRotateInput()
        {

            float rotationThisFrame = rcsThrust * Time.deltaTime;
            if (Input.GetKey(KeyCode.A))
            {
                transform.Rotate(Vector3.forward * rotationThisFrame);
            }
            else if (Input.GetKey(KeyCode.D))
            {
                transform.Rotate(-Vector3.forward * rotationThisFrame);

            }
        }
}

Hi Ihshan,

Where did you test that? In the Unity editor or in your build?

Hi Nina,

I tested in UNITY editor.

Thank you

In that case, Debug.isDebugBuild is always true. See the description in the API.


See also:

Ah I see. So basically we can always see the effect after we deploy the game, right ?
Thanks

What effect do you mean? The build you intend to ship should have “development build” disabled.

Sorry, I mean in order to see when pressing L and C is disabled is not in the editor mode, right ?

Since RespondToDebugKeys gets called only if Debug.isDebugBuild is true, pressing L and C doesn’t “work” if Debug.isDebugBuild is false.

This topic was automatically closed after 2 days. New replies are no longer allowed.

Privacy & Terms