示例#1
0
 public void ProcessAttack()
 {
     if (unitControl.IsDead() || unitControl.IsAttacking() || unitControl.IsWaiting())
     {
         return;
     }
     if (cooldown > 0)
     {
         cooldown -= Time.deltaTime;
     }
     if (!unitControl.GetCurrentEnemy() || unitControl.GetCurrentEnemy().IsDead())
     {
         unitControl.FindNewEnemy(true);
     }
     else
     {
         float distance = (unitControl.GetCurrentEnemy().transform.position - transform.position).sqrMagnitude;
         if (attackRange > distance)
         {
             if (cooldown < 0)
             {
                 Attack();
             }
         }
     }
 }
示例#2
0
 public void ProcessMover()
 {
     if (unitControl.IsDead() || unitControl.IsStunned() || unitControl.IsAttacking())
     {
         return;
     }
     if (unitControl.HasEnemy())
     {
         Transform enemy   = unitControl.GetCurrentEnemy().transform;
         float     minDist = Mathf.Max((unitAttack.attackRange / 2), 2);
         if ((transform.position - enemy.position).sqrMagnitude > minDist)
         {
             MoveTowardsTarget(enemy.position);
         }
         else
         {
             animator.SetBool("isRunning", false);
         }
     }
     else
     {
         Vector3 goalPos = homePosition;
         goalPos.y = transform.position.y;
         if ((transform.position - goalPos).sqrMagnitude > 1)
         {
             MoveTowardsTarget(goalPos);
         }
         else
         {
             animator.SetBool("isRunning", false);
         }
     }
 }