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);
}
}
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.