so for i can get my character to walk into the trigger which plays the sound but it plays again if he walks back in. how do i deactivate the trigger after the sound stops playing? here is the script.
private var soundPlayed : boolean = false;
var Audio : AudioClip; function OnTriggerEnter(col : Collider) //Play Sound if player enters trigger
{ if (Audio) { AudioSource.PlayClipAtPoint(Audio, transform.position);
if(soundPlayed == false)
{
soundPlayed = true;
//Play Audio
}
}
}
You almost got it! Just check the variable soundPlayed before playing anything; if it’s false, play the sound and set the variable to true:
private var soundPlayed : boolean = false;
var Audio : AudioClip;
function OnTriggerEnter(col : Collider){ //Play Sound if player enters trigger
if (!soundPlayed && Audio) { // but only if it has not played before
AudioSource.PlayClipAtPoint(Audio, transform.position);
soundPlayed = true; // sound will not play anymore
}
}