Exemple #1
0
        public override void Update()
        {
            if (target == null || target.IsAlive == false)
            {
                chaseState?.StopState(false);
                chaseState = null;
                StopState();
                return;
            }

            var targetPosition = targetRadius == null ? target.transform.position : targetRadius.GetClosestPoint(target.transform.position);
            var distance       = Vector3.Distance(unit.transform.position, targetPosition);

            if (distance > unit.CurrentJob.attackRange)
            {
                PushChaseState();
                return;
            }

            if (attackTimer >= unit.CurrentJob.attackCooldown)
            {
                unit.ShootProjectile(target);
                attackTimer = 0;
            }
            attackTimer += Time.deltaTime;
        }
Exemple #2
0
 private void ChaseStateFinishedHandler(State state)
 {
     chaseState = null;
 }
Exemple #3
0
 private void PushChaseState()
 {
     chaseState = new ChaseState(unit, target, unit.CurrentJob.attackRange);
     chaseState.OnStateFinish += ChaseStateFinishedHandler;
     PushState(chaseState);
 }