My 'CheatController'

I added an external script to handle all the ‘Cheat stuff’

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class CheatsController : MonoBehaviour
{
    protected GameObject rocket;
    protected bool colisionStatus = true;

    void Start()
    {
        this.rocket = GameObject.Find("Rocket");
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
            this.LoadNextLevel();
        } else if (Input.GetKeyDown(KeyCode.C))
        {
            this.ChangeCollisionStatus(!this.colisionStatus);
        }
    }

    void ChangeCollisionStatus(bool status)
    {
        Debug.Log(status);
        this.rocket.GetComponent<CollisionHandler>().enabled = status;
        this.colisionStatus = status;
    }

    void LoadNextLevel()
    {
        int nextSceneIndex = SceneManager.GetActiveScene().buildIndex + 1;

        if (SceneManager.sceneCountInBuildSettings - 1 < nextSceneIndex)
        {
            nextSceneIndex = 0;
        }
        SceneManager.LoadScene(nextSceneIndex);
    }
}

It is attached to an empty object(created a prefab from it).
Only extra required change was to add on the CollisionHandler.OnCollisionEnter private method a check at the start:

        if (!this.enabled)
        {
            return;
        }

Privacy & Terms