Trigger Once? Need help deactivating a trigger on exit or another solution...

Hey all,

I put together a very basic play sound trigger script and want it to only play once. Currently it plays every time the player enters the trigger (which makes sense). So basically I just want to trigger the sound once and then deactivate the trigger... or is there a better way? Thanks in advance!

Here's my code..basic stuff:

var Audio : AudioClip; function OnTriggerEnter(col : Collider) //Play Sound if player enters trigger

{ if (Audio) { AudioSource.PlayClipAtPoint(Audio, transform.position);

}

}

Hey OldShoolGamer,

You only have to declare a boolean variable at the top like this:

private var soundPlayed : boolean = false;

Then, when you play your sound, you have to check wether the sound was played before:

if(soundPlayed == false)
{
    soundPlayed = true;
    //Play Audio
}

Now it only plays once ;)