private void Update() { distanceToPlayer = Vector3.Distance(player.transform.position, transform.position); WeaponSystem weaponSystem = GetComponent <WeaponSystem>(); currentWeaponRange = weaponSystem.GetCurrentWeaponInUse().GetMaxAttackRange(); bool inWeaponCircle = distanceToPlayer <= currentWeaponRange; bool inChaseCircle = distanceToPlayer > currentWeaponRange && distanceToPlayer <= chaseRadius; bool outsideChaseRing = distanceToPlayer > chaseRadius; if (outsideChaseRing && state != State.patrolling) { StopAllCoroutines(); weaponSystem.StopAttacking(); StartCoroutine(Patrol()); } if (inChaseCircle && state != State.chasing) { StopAllCoroutines(); weaponSystem.StopAttacking(); StartCoroutine(ChasePlayer()); } if (inWeaponCircle && state != State.attacking) { StopAllCoroutines(); weaponSystem.AttackTarget(player.gameObject); } }
bool IsTargetInRange(GameObject target) { float distanceToTarget = (target.transform.position - transform.position).magnitude; return(distanceToTarget <= weaponSystem.GetCurrentWeaponInUse().GetMaxAttackRange()); }