AudioClip problem

Hi m finding some problem when i play audio during firing,

var cross:boolean = true;

var counter :float;

var firesound : AudioClip;

function Start()

{

animation[“fire”].wrapMode = WrapMode.Once;

animation[“Crouch idle”].wrapMode = WrapMode.Once;

}

function Update ()

{

if(cross)

{

StandFire();

}

else

{

crouch();

}

}

function StandFire()

{

transform.animation.CrossFade("fire");// plays stand fire animation
AudioSource.PlayClipAtPoint(firesound, transform.position);
counter += Time.deltaTime;
    if(counter > 4)// after 4 seconds animation changes to "crouch-idle"
    {
       cross = false;
       counter =0.0;
    }

}

function crouch()

{

  transform.animation.CrossFade("Crouch idle");// plays crouch idle animation
   counter += Time.deltaTime;
   if(counter > 4)// after 4 seconds animation changes to "fire"

{
         cross = true;
         counter =0.0;
    }

}

My problem is when “fire” animation is playing, fire sound should come and play only once, but it is playing many times. Plz help me, if there is any other way to achieve this, fire sound must play only when “fire” animation is playing and sound should play only once…

PlayClipAtPoint is the same as instantiating a GameObject with a sound attached. How come you’re not playing it from the player or has it attached as a GameObject childed to the player?

if (!firesound.isPlaying) firesound.Play();

I would do something like this:

var fireSound : AudioSource; //A separate GameObject with AudioSource for this sound
private var fireRate : float = 4.0;
private var nextFire : float = .0;

function Update () {
    if (Input.GetButton("Fire1") && Time.time > nextFire) Fire();
}

function Fire () {
    nextFire = Time.time + fireRate;
    fireSound.Play();
}