audio playing constantly

Hi guys

i have this code where i pick up an object
The sounds keeps repeating annoyingly and only plays normally when i let go of the object. I need the sound to play only when i pick it no matter how many times i do it.

var SpawnTo : Transform; //attaches an object to your character that you want the position of what you picked up to go to, so goes to my bulletspawn
var Object1 : Transform; //The object  you want to translate and move
var dist = 5; //distance at which you can pick things up
var icon : GUITexture;
private var isHolding = false;

 
var audioShield: AudioSource;

 

function Start(){

 

	icon.enabled = false;

 

}









function Update () {
    if(Input.GetKeyDown(KeyCode.Q)){ //if you press 'q', q because closer to finger      
        if(Vector3.Distance(SpawnTo.position, Object1.position) < dist)
		
        {
            isHolding = !isHolding; //changes isHolding var from false to true 
            }
            }
 
    if(isHolding == true){
        Object1.rigidbody.useGravity = false; //sets gravity to not on so it doesn't just fall to the ground
 
        Object1.parent = SpawnTo; //parents the object
 
        Object1.transform.position = SpawnTo.transform.position; //sets transform position
 
        Object1.transform.rotation = SpawnTo.transform.rotation; //sets rotation
        
        shield=GameObject.Find("CFX2_PowerAura");
        Destroy(shield);
    
        icon.enabled = true;
       
        audioShield.Play();
        
        }
        
        
        else{ //if isHolding isn't true
        
            SpawnTo.transform.DetachChildren(); //detach child (object) from hand
            Object1.rigidbody.useGravity = true; //add the gravity back on so resets everything 
   
			icon.enabled = false;        
        
        }
        
}

//GameObject create other Gui texture drag my texture on that and then drag it on the icon variable in the inspector
//spawn to is the empty game object on my character
//object one is the actual object getting picked up

audioShield.Play(); is what is causing it to repeat.

Do your self a favor and create a generic audio playing object. and put this script on it. Add it to the scene and make it inactive.

var audio: AudioSource;

function Start(){
	audio.PlayOneShot();
	Destroy(gameobject, audio.clip.length);
}

Now, instead of playing the audio file over and over, you simply instantiate the game object.

// public variable, assign the object with the shield sound.
var soundObject : GameObject;



// where you would play the sound.
var sound : GameObject = Instantiate(soundObject, transform.position, Quaternion.identity);
sound.SetActive(true);

far simpler and less putting sounds on individual files scripts. just use the same sound objects over and over again, or add new ones for different sound effects.

Cutsie trick:
Add the sound, puff of smoke and a shoe print, and place it wherever a foot falls… instant foot fall, and just have it fade or disapear after a short time.