I already got as far as 51, How To Trigger Particles, ignoring the error, but it’s getting annoying, and I everything I did with the bool just isn’t working and I have no idea why. This is my code.
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
[SerializeField] float levelLoadDelay = 2f;
[SerializeField] AudioClip crash;
[SerializeField] AudioClip success;
[SerializeField] ParticleSystem crashParticles;
[SerializeField] ParticleSystem successParticles;
AudioSource audioSource;
bool isTransitioning = false;
void Start () {
audioSource = GetComponent<AudioSource>();
}
private void OnCollisionEnter(Collision other) {
if (isTransitioning) { return; }
switch (other.gameObject.tag) {
case "Friendly":
Debug.Log("We hit our safe zone we are now ready to thrust.");
break;
case "Finish":
StartSuccessSequence();
break;
default:
StartCrashSequence();
Debug.Log("Brace for impact, we are about to crash into--");
break;
}
}
void StartSuccessSequence() {
bool isTransitioning = true;
audioSource.Stop();
audioSource.PlayOneShot(success);
successParticles.Play();
GetComponent<Movement>().enabled = false;
Debug.Log("We have now reached our designated location.");
Invoke ("LoadNextLevel", levelLoadDelay);
}
void StartCrashSequence() {
bool isTransitioning = true;
audioSource.Stop();
audioSource.PlayOneShot(crash);
crashParticles.Play();
GetComponent<Movement>().enabled = false;
Invoke ("ReloadLevel", 1f);
}
void LoadNextLevel() {
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings) {
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
Debug.Log("NEXT");
}
void ReloadLevel() {
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
}