I want an audio clip to play when two cars collide but I can't make it so the audio doesn't play at the beginning. If it doesn't play then, then it won't play at all. Any suggestions as to how I can script this. I can't figure out anything that doesn't give me an error.
making sure theres an 'audio source' component attached to the object that has this script.
var myClip : AudioClip;
function OnCollisionEnter(collision : Collision) {
audioClip = myClip;
audioPlay();
}
I havent tested it, but it's along those lines.
- C
hey if you want to play an audio source you can do the following:
var MyAudioClip : AudioClip;
function OnCollisionEnter (hit:Collision ){
AudioSource.PlayOneShot(MyAudioClip, transform.position );
}
if you want the sound to be 2 dimensional make sure that in unity when you drag the audio clip in to the inspector look for it and click on it. once you do that a list of options will become available on the sound look for where it says 3d sound tick that of and hit apply. The reason this is important is because if you leave 3d sound on and you move the player the sound starts to fade away when you are far away from the trigger :)
hope this helps.