Monday, June 27, 2011

how to trigger a song for the player


// This is a public variable so you have to assign the audio clip you wish to play in the Inspector
var HaloTheme : AudioClip;

// Make a box, delete the mesh renderer, and make the Box Collider a trigger by selecting 'Is Trigger'
// Then expand it to enclose the whole area you wish it to cover, ie a room.
function OnTriggerEnter (other : Collider) {
// Make sure your character is tagged 'player'
if (other.gameObject.tag == "player") {

// Plays the audio that you want...
audio.Play(HaloTheme);
}
}

// Simply makes it so the object can play audio
@script RequireComponent(AudioSource)
Also, i didn't put a comment in there for it, but on the Audio Source comopnet that is added, make sure you have it set to Loop, if you want it to loop that is.

No comments:

Post a Comment