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