Ok, my problem is that when I give a value greater than 0f in waitforseconds it’s distorting my sound/audiofile.
. If yeld it 's 0 it works properly but enemy is destroyed and does not have enough time to show animation. Sorry for my bad english. What I must do? I’m in a hurry because I want to release this game in 2 days.
void Start () {
anim = GetComponent ();
audio = GetComponent ();
}
// Update is called once per frame
void Update () {
if (enemyHealth <= 0) {
offset = player.transform.position;
//Instantiate (deathEffect, transform.position, transform.rotation);
anim.SetBool ("Imp", true);
ScoreManager.AddPoints (pointsonDeath);
//AudioSource.PlayClipAtPoint (death, offset, 0.7f);
verifica = true;
StartCoroutine (KillOnAnimationEnd ());
} else {
anim.SetBool ("Imp", false);
offset = player.transform.position;
}
}
public void giveDamage(int damageToGIve)
{
enemyHealth -= damageToGIve;
}
private IEnumerator KillOnAnimationEnd() {
AudioSource.PlayClipAtPoint (death, offset, 0.7f);
yield return new WaitForSeconds (0.4f);
Destroy (gameObject);
}