- Home /
Audio not playing...
Hi! I have this tomato thinngy and when you shoot it it needs to make a sound. The tomato has collider and audio source applied, along with this script.
var die : AudioClip;
function OnTriggerEnter(other : Collider){
audio.Play(die);
}
Plus I have the die sound applied to both the script and source. Help please.
Answer by Tomer-Barkan · Dec 15, 2013 at 06:51 AM
An AudioClip is a sound file, but in order to play it you need a player, which in Unity is an AudioSource. The AudioSource is a component that can be attached to any object, but for simplicity, if you just want to play a clip, you can use the static method AudioSource.PlayClipAtPoint. You have to tell it where in the world to play the clip (best put it next to the camera if you don't want 3d sound effect)
var die : AudioClip;
function OnTriggerEnter(other : Collider){
AudioSource.PlayClipAtPoint(die, Camera.main.transform.position);
}
Your answer
Follow this Question
Related Questions
Audio continuation through two scenes 3 Answers
Playing Sound 2 Answers
Audio clip not playing 1 Answer
Audio playing problem 1 Answer
Multiple audio sources; Unity won't let me attach in the inspector 2 Answers