Sound system not working correctly

My Script is not working properly. I have multiple prefabs called SoundBoxes, if my character collides with them I would like to either play a random sound from a folder or a selected sound.(Just play the sound selected in the AudioSource) My script does not seem to work properly. It never plays the sound I want and sometimes executes both if and else… I noticed that the PlaySound function seems to rune twice although it should not.

I would be really happy if someone could tell me how to make this look like script(with the blue if and var)

Thank you,
Pit

Code:

#pragma strict
//
// play a random sound from a folder
//
 
var isPlaying : boolean = false;
var thisSound : AudioSource;
var myClips : Object[];
var hasPlayed : boolean = false;


var playSelected : boolean;
 
function Start(){
    myClips = Resources.LoadAll("Sounds/Voices",AudioClip);
}




function Update()
{


if (StaticGameData.restart == true)
{ResetObject();}




}


function OnTriggerEnter(cc : Collider){


    if(cc.gameObject.tag == "Player"  !hasPlayed){
        PlaySound();


    }


    


}
function OnTriggerExit(cc : Collider){
hasPlayed = true;
}
function PlaySound()
{
    if(playSelected == false)
    {
        audio.clip = myClips[StaticGameData.whatSound];
        audio.Play();
        Debug.Log("has played normal");
            
            
        if (StaticGameData.whatSound+1 == myClips.Length)
        {
            StaticGameData.whatSound = 0;
        }
        else
        {
            StaticGameData.whatSound = StaticGameData.whatSound +1;
        }
        
    }
    else
    {
        audio.Play();
        Debug.Log("has played selected");
    }
        


            
        
}

function ResetObject()
{
    hasPlayed = false;
    StaticGameData.restart = false;
}

Is it possible that the play controller has multiple physics objects associated with it, and so you are getting an on collision for each one? Or perhaps you are colliding on it, bouncing back, and then pushing into it again?

Perhaps adding a check to see if the player is what hit it would help. As well, it could be useful to put a reactivation delay on it. For example, perhaps it should only ever be able to play a sound every 0.5 seconds.

Let me know if that helps.