|
Java Code - Audio
[Back]
Code:
//To play a sound you first need a Audiosource on that object, on audio source you can leave it to none
var sound : AudioClip; //Hold a audioclip
function Update ()
{
audio.PlayOneShot(sound); //Play Sound
or
audio.PlayOneShot(sound, 0.7); //Play Sound at volume 0.7
//(sound) is the name of the var
}
//How to wait for a Sound to stop
function Start
{
Sound(); //Go to function Sound
}
//Then in function sound
function Sound()
{
yield WaitForSeconds (audio.clip.length); //Wait for Audio to stop
//Wait then do THIS
}
//Other Stuff
audio.clip = sound; //make the audio.clip the sound var
audio.Play();
var audiosource : AudioSource; //Hold audio source
audiosource.enabled = false; //Turn on or off Audiosource
var sound : AudioClip; //Hold a audioclip
function Update ()
{
audio.PlayOneShot(sound); //Play Sound
or
audio.PlayOneShot(sound, 0.7); //Play Sound at volume 0.7
//(sound) is the name of the var
}
//How to wait for a Sound to stop
function Start
{
Sound(); //Go to function Sound
}
//Then in function sound
function Sound()
{
yield WaitForSeconds (audio.clip.length); //Wait for Audio to stop
//Wait then do THIS
}
//Other Stuff
audio.clip = sound; //make the audio.clip the sound var
audio.Play();
var audiosource : AudioSource; //Hold audio source
audiosource.enabled = false; //Turn on or off Audiosource