Having a bit of an issue. My sounds play fine on thrust. However, crash and win sounds give a warning stating “PlayOneShot was called with a null AudioClip”. Code is below. Any help would be appreciated.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
AudioSource audioSource;
[SerializeField] float loadDelay;
[SerializeField] AudioClip crashSound;
[SerializeField] AudioClip winSound;
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
// Start is called before the first frame update
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
break;
case "Finish":
SuccessSequence();
break;
default:
CrashSequence();
break;
}
}
void SuccessSequence()
{
//add particle effect
//add crash sound
GetComponent<Movement>().enabled = false;
audioSource.PlayOneShot(winSound);
Invoke("NextLevel", loadDelay);
}
void CrashSequence()
{
//add particle effect
//add crash sound
GetComponent<Movement>().enabled = false;
audioSource.PlayOneShot(crashSound);
Invoke("ReloadLevel", loadDelay);
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
void NextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}