x


Changing current audio on trigger.

I have some simple bird song attached to my character controller (Audio Source) and wanted to know if there was a way to change the current audio source when a trigger is hit to something else. For instance:

Bird song is playing > When trigger is hit > Bird song stops > Zombie Sound effect takes over.

 function OnControllerColliderHit (hit : ControllerColliderHit)
    {
    if (hit.gameObject.tag == "Cube")
audio.stop;
audio.change = resources.load ("From File");

Or something similar.

more ▼

asked Nov 30 '10 at 11:32 AM

Rukey4 gravatar image

Rukey4
3 3 4 8

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

1 answer: sort voted first

Take a look at the answers to this question: http://answers.unity3d.com/questions/4795/what-is-the-script-code-on-how-to-trigger-a-song-for-the-player-to-listen-to

It's not the same question as yours, but nonetheless, the code there shows how to play an audio clip that was assigned via the Unity inspector. You can easily declare two audio clips, set one the the bird song and the other to the zombie, and play either one whenever you want.

more ▼

answered Nov 30 '10 at 04:12 PM

Bampf gravatar image

Bampf
5k 8 19 49

(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:

x3459
x1027
x984
x379
x72

asked: Nov 30 '10 at 11:32 AM

Seen: 1824 times

Last Updated: Nov 30 '10 at 11:32 AM