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