enemy die sound problem

I have put a sound on the enemy health script and I write about if the health = 0, then play the sound. but the problem is it generate more than one sound when it's health is 0. Below is the script i write. How can I fix it?

var Health : int = 20;

var deadsound : AudioClip; var Playaudio : int = 2; var Recount : float; var effectsound : Transform;

function Start (){ animation["hit"].wrapMode = WrapMode.Once; animation["hit"].layer = 2; animation["die"].wrapMode = WrapMode.Once; animation["die"].layer = 2; Recount = 0; }

function Update () { if (Health == 0){ animation.Play("die"); Recount = 1; audio.PlayOneShot(deadsound); Destroy(gameObject, 3); } }

Maybe add

var PlayedDeathSound : bool;

function Start()
{
  PlayedDeathSound = false;
  ... (the rest of your Start here)
}

function Update()
{
  if(Health == 0)
  {
    ... (rest of your death code here)
    if(!PlayedDeathSound)
    {
      PlayedDeathSound = true;
      audio.PlayOneShot(deadsound);
    }
  }
}

But if you destroy the object when you play the sound, it means there's probably another issue with your code, and my solution will just patch the symptom without fixing the issue.