Hello, I was following the instruction on the debug lecture to the T and I seem to be stuck on turning my collisions back on. I know the code works since I can change the levels but I cannot figure out why the collisions aren’t working anymore.
public class CollisonHandler : MonoBehaviour
{
//PARAMATERS
[SerializeField] float LevelDelay = 2f;
[SerializeField] AudioClip Success;
[SerializeField] AudioClip Crash;
[SerializeField] ParticleSystem ParticleSuccess;
[SerializeField] ParticleSystem ParticleCrash;
//CACHE
AudioSource audioSource;
//STATE
bool isTransitioning = false;
bool collisionDisabled = false;
void Start()
{
audioSource = GetComponent<AudioSource>();
}
void Update()
{
RespondToDebugKeys();
}
void RespondToDebugKeys()
{
if (Input.GetKeyDown(KeyCode.L))
{
LoadNextLevel();
}
else if (Input.GetKeyDown(KeyCode.C))
{
collisionDisabled = !collisionDisabled;
}
}
void OnCollison(Collision Other)
{
if (isTransitioning || collisionDisabled)
{
return;
}
switch (Other.gameObject.tag)
{
case "Friendly":
Debug.Log("This thing is friendly");
break;
case "Finish":
StartSuccessSequence();
break ;
case "Fuel":
Debug.Log("Fuel Added");
break;
default:
StartCrashSequence();
break;
}
}
void StartSuccessSequence()
{
isTransitioning = true;
audioSource.Stop();
audioSource.PlayOneShot(Success);
ParticleSuccess.Play();
GetComponent<Movement>().enabled = false;
Invoke("LoadNextLevel", LevelDelay);
}
void StartCrashSequence()
{
isTransitioning = true;
audioSource.Stop();
audioSource.PlayOneShot(Crash);
ParticleCrash.Play();
GetComponent<Movement>().enabled = false;
Invoke("ReloadLevel", LevelDelay);
}
void LoadNextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
}
Please if anyone one could point me in the right direction I would greatly appreciate it! Great course so far!