Ejemplo n.º 1
0
    void Update()
    {
        if (!isAlive)
        {
            return;
        }
        healthBar.gameObject.SetActive(unit.isSelected);
        healthBar.health = health;

        if (unit.formation)
        {
            currentTowerTarget = unit.formation.currentTowerTarget;
        }

        if (currentTowerTarget && isNearTower())
        {
            order = Commands.Attack;
            currentTowerTarget.GetComponent <Tower> ().Attack(attackPower * Time.deltaTime);
        }
        else if (order == Commands.Attack)
        {
            order = Commands.None;
        }

        animator.SetBool("isWalking", false);
        animator.SetBool("isAttacking", false);
        switch (order)
        {
        case Commands.None:
            break;

        case Commands.Goto:
            animator.SetBool("isWalking", true);
            break;

        case Commands.Attack:
            animator.SetBool("isAttacking", true);
            break;
        }

        if (health <= 0)
        {
            // TODO play death animation
            unitSelection.unitsDeadCount++;
            isAlive = false;
            Destroy(healthBar.gameObject);
            Destroy(GetComponent <FollowNavAgent>().agent.gameObject);
            if (unit.formation)
            {
                unit.formation.RemoveUnit(unit);
            }
            unitSelection.DeselectUnit(unit);
            Destroy(this.gameObject);
        }
    }