I’ve put the Debug Keys into a separate script, also added Level Reload. For some reason collision toggling is inconsistent. Could this be because it’s in a separate script from movement? I’ve noticed it’s most inconsistent while in-motion. So when Spacebar or A/D are pushed down.
using UnityEngine.SceneManagement;
using UnityEngine;
public class DebugKeys : MonoBehaviour
{
Collider boxCollider;
void Start()
{
boxCollider = GetComponent<Collider>();
}
void Update()
{
DebugActions();
}
void DebugActions() {
if (Input.GetKey(KeyCode.L))
{
LoadNextLevel();
}
if (Input.GetKey(KeyCode.P))
{
ReloadLevel();
}
if (Input.GetKey(KeyCode.C))
{
ColliderToggle();
}
}
private void ColliderToggle()
{
boxCollider.enabled = !boxCollider.enabled;
Debug.Log("Collider.enabled = " + boxCollider.enabled);
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex +1;
if(nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}