Game Development Reference
In-Depth Information
3.
Get a reference to the BackgroundMusic script component attached to the
Audio game object and call the PlayVictoryMusic() function, which you
will write next. Another approach would have been to stop the background
music, then play the victory music audio clip using this game object and
script, but since it is background music, for the sake of keeping your project
organized it is a better practice to keep it contained by a single dedicated
game object.
Save the script, then attach it to the Fantasy Victory (free) game object. Select the Fantasy Victory
(free) game object in the Hierarchy, then drag the Audio game object from the Hierarchy into the
Background Music field of the Victory Music script component.
In MonoDevelop, return to the BackgroundMusic script and add the following lines of code:
#pragma strict
public var musicLoop : AudioClip;
private var introMusicIsPlaying : boolean = true;
private var looping : boolean = false;
public var victoryMusic : AudioClip;
function Start () {
PlayBackgroundMusic();
}
function Update() {
}
function PlayBackgroundMusic () {
}
function LoopBackgroundMusic () {
}
function PlayVictoryMusic () {
if(audio.isPlaying == true) {
audio.Stop();
}
audio.clip = victoryMusic;
audio.Play();
}
Search WWH ::




Custom Search