Why AudioSource.PlayClipAtPoint playing 100 instances of my SoundFX?

Im trying to play a sound effect when a tree object falls over and gets destroyed.

Im calling this code:

    public void DestroyTree ()
    {
        AudioSource.PlayClipAtPoint(collectSFX, transform.position);
        DestroyObject (this.gameObject, 3f);
    }

But it just seems to play 100 instances of the sfx file all playing simultaneously.

3128339--236920--upload_2017-7-1_1-18-24.png

Just would like it to play once. Seems like that should be the default behavior and how it seems to work in other scripts…

how is DetroyTree called? Paste the code for that call too… my guess here is you’re making multiple calls to DestroyTree and not realizing it.

Your will be right i suspect. Im currently calling it in a co routine, and grabbing the script from the tree gameobject which has the DestroyTree () function.

private void choptree()
    {
        if(!playerAgent.pathPending)
        {
            if (Vector3.Distance (playerAgent.destination, this.transform.position) < 1) {
                playerAgent.speed = 0;
                SelectObjectBool = false;
                Vector3 dir = currentInteractable.transform.position - transform.position;
                dir.y = 0;
                rot = Quaternion.LookRotation (dir);
                transform.rotation = Quaternion.Lerp (transform.rotation, rot, 1f * Time.deltaTime);
             
                animator.SetBool ("isChopping", true);
                animator.SetBool ("isWalking", false);
                hitObject.GetComponent<animatedpalm> ().anim.SetBool ("TreeFall", true);
                StartCoroutine (PlayChopInterval ());
                moveFSM = MoveFSM.idle;
            }
     IEnumerator PlayChopInterval()
    {
        yield return new WaitForSeconds (2f);
        hitObject.GetComponent<animatedpalm>().DestroyTree ();
        animator.SetBool ("isChopping", false);
        animator.SetBool ("isIdle", true);
       
    }

But i also tried inserting “AudioSource.PlayClipAtPoint(collectSFX, transform.position);” outside of the co-routine, attached to this script and not the tree gameobject and still the same results scratches head. I have much to learn

Thanks
cstooch, You got me thinking how it was bieng called, and i can see now, I didn’t have any states/code after the co routine was complete. Seems to be working now.

Sounds good, glad you were able to find that!