- Home /
OneShot Audio not playing
Here is my code
var lightturnon: AudioClip;
function OnTriggerExit(){
gameObject.light.enabled = true;
audio.PlayOnShot(lightturnon);
}
The lights turn on, but no sound plays, i have added the sound to the object. The error in game i get is Missingmethodexeption : UnityEngine.AudioSource.PlayOneShot
Anyhelp appritiated
Comment
Thankyou thats right, i changed it but it still doesn't play :|
Answer by gregzo · Aug 01, 2013 at 02:11 PM
audio.anything means you are accessing the AudioSource component of the GameObject. If you do not have an AudioSource attached, expect exceptions.
PlayOneShot is a bit of a special case, since it will create an AudioSource if needed, but it still needs at least one attached to the GameObject.
Edit : hadn't spotted the typo, lol...
Your answer
![](https://koobas.hobune.stream/wayback/20220613111341im_/https://answers.unity.com/themes/thub/images/avi.jpg)