- Home /
Question by
dalekandjedi · Aug 08, 2012 at 08:54 PM ·
gameobjectcollideraudio
How to make audio play when passes a collider
I would like to have a audio clip play as something goes though a collider like this object which is a robot (which has the name car) and when it falls in the pit i have a audio snip it so when it passes the collision it will play is there away to do that?
so like it has a gameobject which has a cube collider and when the robot passes it when it falls in the pit it activates the audio?
Comment
Answer by dalekandjedi · Aug 08, 2012 at 09:58 PM
var audio1 : AudioClip;
var audio2 : AudioClip;
function OnTriggerEnter (other : Collider) { if (other.tag == "Car"){ audio.clip = audio1; audio.Play(); }
//Play another sound
audio.clip = audio2;
audio.Play();
}
But it plays for all objects the passes the collider
Your code isn't formatted well here, but I'm noticing that you have an if, but no else. You might want one.