I have a sound manager which i learnt from a tutorial
it was working, then i saved everything and restarted, and it wasnt working, had the below error.
if i recreate the script and apply it, it works, but as soon as i restart unity and my project, im getting an error:
NullReferenceException: Object reference not set to an instance of an object
and it takes me to this line:
audioSrc.PlayOneShot(raceStart);
here is my entire sound manager script
any ideas why it works and then stops?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class soundManager : MonoBehaviour
{
public static AudioClip raceStart;
static AudioSource audioSrc;
// Start is called before the first frame update
void Start()
{
raceStart = Resources.Load<AudioClip>("racestart");
audioSrc = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
}
public static void PlaySound(string clip)
{
switch (clip)
{
case "racestart":
audioSrc.PlayOneShot(raceStart);
break;
}
}
}