Audio help.

I Need help with an script in an audio of me. When im touching the brick the audio will play but i need to insert a line of script so that when i have touched the brick the sound cant be player again. :

#pragma strict

var loudBang:AudioClip;

function OnTriggerExit(o:Collider){
Debug.Log(“The trigger fired”);



This is JS.
Where do i put the line of script so that when i touch it it cant be played again.

MORE INFO ( If necesarry ) :

Its a gameobject
Its a audio source
I did the script in JS


  • Vince

I would suggest using booleans to control your music playing:

// at the top with loudbang
var loudBang : AudioClip;
var touchedWall : boolean = false;

// then in your OnTriggerExit() function
function OnTriggerExit(col : Collider)
    Debug.Log("The trigger fired");
    if (!touchedWall) // if touchedWall is false
        touchedWall = true;

// maybe in your OnTriggerEnter() function you should add
function OnTriggerEnter(col : Collider)
    touchedwall = false;