Hello Unity answer community,
I trying to trigger a sound once a player enters a trigger it works but im having some problem, the sound will start when the game starts up but it still plays when the player triggers it and it does not play one, every time the player walks into the trigger the sound will play.
Things i need help with
-
play sound only once
-
stop sound from playing when game is started only play sound when trigger is entered
Here is what my script looks like :
#pragma strict
var flashClip:AudioClip;
var isFlash = false;
function OnTriggerEnter (o:Collider) {
Debug.Log("The Trigger fired enter");
isFlash = true;
}
function OnTriggerExit (o:Collider){
Debug.Log("the trigger fired");
if(isFlash == true) {
playFlash ();
}
}
function playFlash () {
audio.PlayOneShot(flashClip);
isFlash = false;
}
Thank you for taking your time,
Have a nice day/night.