Hi
I have added the two AudioClips to the Collision script with plus the audio source.
But it won’t play when I hit an object. When I hit an object or get to the finish i get this error.
Here is my code
public class CollisionChecker : MonoBehaviour
{
//PAREMTERS
[SerializeField] float LevelLoadDelay = 2f;
public AudioClip DeadSoundPlay;
public AudioClip YouMadeIt;
// CACHE
AudioSource audioSource;
void start()
{
audioSource = GetComponent<AudioSource>();
}
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("this thing is nice");
break;
case "Finish":
StartSuccesSequenceNOW();
break;
default:
StartCrashOfShip();
break;
}
}
//When you win Go to next level
private void StartSuccesSequenceNOW()
{
audioSource.PlayOneShot(YouMadeIt);
// totdo add particals
GetComponent<Movment>().enabled = false;
Invoke("LoadTheNextlevel",LevelLoadDelay);
}
//If you hit somthing reload level.
void StartCrashOfShip()
{
GetComponent<Movment>().enabled = false;
Invoke ("ReloadLevel", LevelLoadDelay);
// totdo add particals
audioSource.PlayOneShot(DeadSoundPlay);
}
void LoadTheNextlevel()
{
int currentLevelIndex = SceneManager.GetActiveScene().buildIndex;
int nextLevelIndex = currentLevelIndex + 1;
if (nextLevelIndex == SceneManager.sceneCountInBuildSettings)
{
nextLevelIndex = 0;
}
SceneManager.LoadScene(nextLevelIndex);
SceneManager.LoadScene(currentLevelIndex + 1);
}
void ReloadLevel()
{
int currentLevelIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentLevelIndex);
}
}