Example #1
0
    IEnumerator TakeDamage(int damage)
    {
        isHit = true;
        anim.Play("skeleton_hit");
        Debug.Log("hp left: " + health);
        health -= damage;
        yield return(new WaitForSeconds(.25f));

        isHit = false;
        Debug.Log("hp left: " + health);
        if (health <= 0)
        {
            isDead = true;
            anim.Play("skeleton_dead");
            FindObjectOfType <AudioManager>().Play("SkeleDeath");
            yield return(new WaitForSeconds(.5f));

            es.SkeleDeath();
            if (Random.Range(0, 12) < 2)
            {
                Vector3 hpPosition = new Vector3(0, .35f, 0);
                Instantiate(hpPotion, gameObject.transform.position + hpPosition, Quaternion.identity);
            }
            Destroy(gameObject);
        }
    }