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); } }