Hello everyone!
So my beautiful rocket is playing thrusting and finish sound without any problem but when I try to get it to play crash sound it’s not working at all, here is my code:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ColisionHandler : MonoBehaviour
{
[SerializeField] AudioClip finishSound;
[SerializeField] AudioClip crashSound;
[SerializeField] float delayTime = 1f;
AudioSource audioSource;
const string FRIENDLY = "Friendly";
const string FINISH = "Finish";
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
private void OnCollisionEnter(Collision collision)
{
switch (collision.gameObject.tag)
{
case FRIENDLY:
Debug.Log("Friendly");
break;
case FINISH:
Debug.Log("Finish");
StartSuccessSequence();
break;
default:
Debug.Log("Default");
StartCrashSequence();
break;
}
}
private void StartSuccessSequence()
{
audioSource.PlayOneShot(finishSound);
//TODO add particle effect upon crash
GetComponent<Movement>().enabled = false;
Invoke("LoadNextLevel", delayTime);
}
private void StartCrashSequence()
{
Debug.Log("Should play crash sound");
audioSource.PlayOneShot(crashSound);
//TODO add particle effect upon crash
GetComponent<Movement>().enabled = false;
GetComponent<AudioSource>().enabled = false;
Invoke("ReloadLevel", delayTime);
}
private void ReloadLevel()
{
SceneManager.LoadScene(GetCurrentSceneIndex());
}
private void LoadNextLevel()
{
int nextSceneIndex = GetCurrentSceneIndex() + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
private int GetCurrentSceneIndex() => SceneManager.GetActiveScene().buildIndex;
}
I tried changing my crashing sound to finish one but still it’s not playing. Also I put the debug logs and everything looks fine, I get the right messages. Idk what’s wrong, and what else I can check, could I kindly ask for any advice?