- Home /
MissingMethodException: 'UnityEngine.AudioClip.Play'
I'm new to using Unity and to programming in general, and I'm trying to get a sound clip to play when a character runs into a collider, but Unity gives me the error "MissingMethodException: Method Not Found: 'UnityEngine.AudioClip.Play'." I'm not really sure what that means or what I can do to fix it.
This is the code I'm using:
var aSound : AudioClip;
var targetObject : GameObject;
function OnCollisionEnter(collision:Collision){
if(collision.gameObject.tag == "Player"){
audio.PlayOneShot(aSound);
}
}
Answer by Statement · Apr 04, 2012 at 04:37 PM
It means the method is missing or not found, the error message says it really.
If you check the docs for AudioClip, it does not have a method called PlayOneShot
.
Maybe you meant to use AudioSource.PlayOneShot instead.
Answer by Harhunt · Apr 05, 2012 at 07:46 AM
This is what I get for trying to work without my designated programmer, haha. Well, AudioSource just made more problems, but I did work out a solution:
var aSound : AudioClip; var targetObject : GameObject; private var setTrigger : boolean = false;
function OnTriggerEnter(){
if (!setTrigger) {
audio.PlayOneShot(aSound);
setTrigger = true;
}
}
This is probably a roundabout way of doing it, but I'm more of a designer, and this works, so I'm not complaining. My characters now run through the collider and trigger dialog without repeating it when they go back through it. Sweet.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065859im_/https://answers.unity.com/themes/thub/images/avi.jpg)