- Home /
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.
Answer by Bampf · Nov 30, 2010 at 04:12 PM
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.