- Home /
How to make audio play when passes a collider
Hey sorry I didnt explain this right lol,
Cos i have a trigger but i need it to activate a sound when a Car goes over it cos i have cubes that can move everywhere but when they touch the trigger it activates the sound which i dont want i only want the Car to activate it
var audio1 : AudioClip;
var audio2 : AudioClip;
function OnTriggerEnter (other : Collider) {
if (other.gameObject.name == "Car"){
audio.clip = audio1;
audio.Play();
}
//Play another sound
audio.clip = audio2;
audio.Play();
}
Answer by darthbator · Aug 09, 2012 at 02:49 AM
You appear to have that second clip playing audio outside of the OnTriggerEnter event.
So how would i make it work only for the object in the game?
Answer by zero84085 · Aug 11, 2012 at 08:08 AM
var audio1 : AudioClip
var audio2 : AudioClip;
function OnCollisionEnter (other : Collider) {
if (other.gameObject.name == "Car"){
audio.clip = audio1;
audio.Play();
}else{
audio.clip = audio2;
audio.Play();
}
if this help you rate it positive =D
Your answer
![](https://koobas.hobune.stream/wayback/20220613075411im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Play Sound on trigger 2 Answers
Detect if out of trigger 2 Answers
I want my trigger sound only to play once! 0 Answers
Play sound on trigger, sound is coming from the trigger 1 Answer