I have a basic audio script, and it works fine. I am working on a horror game, so it would be weird to here the same scream by moving through the same location. I would like to make it so that the sound only plays once going through the collider.
Here is my script, sorry I am a noob at Scripting
#pragma strict
var flushClip:AudioClip;
var flush1Clip:AudioClip;
var isFlush = false;
var hasPlayed = false;
function OnTriggerEnter(o:Collider){
Debug.Log(“The trigger fired enter”);
isFlush = true;
hasPlayed = true;
}
function OnTriggerExit(o:Collider){
Debug.Log(“The trigger fired”);
if(isFlush == true) {
playFlush();
}
if(!hasPlayed == true){ //play audio hasPlayed = true;
}
}
function playFlush(){
audio.PlayOneShot(flushClip);
isFlush = false;
hasPlayed = false;
}
function playFlush1(){
audio.PlayOneShot(flushClip);
isFlush = true;
hasPlayed = true;
}
Any assistance would be appreciative. Thank you!