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; }
private void ChaseStateFinishedHandler(State state) { chaseState = null; }
private void PushChaseState() { chaseState = new ChaseState(unit, target, unit.CurrentJob.attackRange); chaseState.OnStateFinish += ChaseStateFinishedHandler; PushState(chaseState); }