- Home /
Play sound on trigger, sound is coming from the trigger
I'm a bit of a noob... I'm using this script to animate an object and play a sound, the animation works fine but the sound is coming from the trigger not the animated object. Any help is very much appreciated.
var Sound : AudioClip; var Animator : GameObject;
private var hasPlayed = false;
function OnTriggerEnter(){ if(!hasPlayed){ audio.PlayOneShot(Sound); hasPlayed = true;
Animator.animation.Play("plane");
}
}
Answer by mattssonon · Sep 04, 2013 at 02:48 PM
You are assigning the audio clip to the trigger when you use var Sound : AudioClip;
. What you need to do is assign a GameObject which has the AudioClip component and call it doing something like this:
var AudioClipContainer : GameObject;
AudioClipContainer.GetComponent(AudioClip).PlayOneShot(Sound);
No problem, feel free to set my answer as the correct one if you feel that it helped.
Your answer
Follow this Question
Related Questions
animation and sound on collide 1 Answer
Activating One Part of An Animation 2 Answers
How an Enemy could activate a Sound? 3 Answers
Play sound on anim frame 1 Answer
How to stop animation on trigger? 1 Answer