예제 #1
0
    void Update()
    {
        Debug.Log("Health is: " + enemy.GetHealth());
        // if (enemy.GetHealth() < 0)
        // {
        //     Destroy(enemy.GetGameObject());

        // }
        if (enemy.GetAttackState())
        {
            //    Destroy(hitTower.gameObject);
            //    if (hitTower.NotDead())
            //    {
            //        hitTower.SendMessage("AddHealth", -enemy.GetDamage());
            //    }
        }
        else
        {
            float step = speed * Time.deltaTime; // calculate distance to move
            if (towerTarget != null)
            {
                float distance = Vector3.Distance(transform.position, towerTarget.position);
                if (distance < 4.0f)
                {
                    enemy.SetAttackState(true);
                }
                transform.position = Vector3.MoveTowards(transform.position, towerTarget.position, step);
            }
            else
            {
                transform.position = Vector3.MoveTowards(transform.position, new Vector3(90, 7, 90), step);
            }
        }
    }
예제 #2
0
    public void AddHealth(int amount)
    {
        enemy.AddHealth(amount);

        if (enemy.GetHealth() < enemy.GetMaxHealth() && healthBar == null)
        {
            healthBar = Instantiate(healthBarPrefab, Game.progressCanvas.transform);
            healthBar.GetComponent <HealthScript>().healthable = enemy;
        }
    }