I’m trying to load an audio clip that’s in my assets directory and play it. Here is my C# script:
if (Input.GetKeyDown(KeyCode.X))
{
audioSource = gameObject.GetComponent<AudioSource>();
Debug.Log((audioSource == null) ? "Audio source is null" : "Audio Source is not null");
string path = "Sounds/Aurora/Aurora_IGSSin";
Debug.Log(path);
sound = (AudioClip)Resources.Load(path, typeof(AudioClip)) ;
Debug.Log((sound == null) ? "Sound is null" : "Sound is not null");
}
//Output:
//Audio source is not null
//Sounds/Aurora/Aurora_IGSSin
//Sound is null
Attached is a picture of my project directory. I’ve seen 90 different posts and tried this 81 different ways, including using the file extension in the path, omitting the directory and only including the file name, omitting (AudioClip)
before Resources.Load()
, using as AudioClip
rather than typeof(AudioClip)
and none of it has worked.
Please, someone help me before I pull my hair out over this.