x


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?

more ▼

asked Aug 08 '12 at 08:54 PM

dalekandjedi gravatar image

dalekandjedi
30 3 6 13

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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

more ▼

answered Aug 08 '12 at 09:58 PM

dalekandjedi gravatar image

dalekandjedi
30 3 6 13

Your code isn't formatted well here, but I'm noticing that you have an if, but no else. You might want one.

Aug 08 '12 at 10:54 PM Screenhog
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3416
x2165
x1762
x1058

asked: Aug 08 '12 at 08:54 PM

Seen: 234 times

Last Updated: Aug 08 '12 at 10:54 PM