private void CheckRange() { if (Vector3.Distance(enemy.GetTargetPosition(), enemy.transform.position) > (enemy.attack.attackRange - enemy.attack.attackRangeOffset)) { ToChasingState(); } }
private void Look() { RaycastHit hit; Vector3 enemyToTarget = new Vector3(enemy.GetTargetPosition().x - enemy.eyes.position.x, 0, enemy.GetTargetPosition().z - enemy.eyes.position.z); if (Physics.Raycast(enemy.eyes.position, enemyToTarget, out hit, 100f, Layers.NonEnemy) && hit.collider.gameObject.CompareTag("Player")) { if (Vector3.Distance(enemy.GetTargetPosition(), enemy.transform.position) <= (enemy.attack.attackRange - enemy.attack.attackRangeOffset)) { ToAttackingState(); return; } } else { // If chasing target is not in our vision, check if another player is foreach (GameObject player in enemy.GetVisiblePlayers()) { enemyToTarget = new Vector3(player.transform.position.x - enemy.eyes.position.x, 0, player.transform.position.z - enemy.eyes.position.z); if (Physics.Raycast(enemy.eyes.position, enemyToTarget, out hit, 100f, Layers.NonEnemy) && hit.collider.gameObject.CompareTag("Player")) { enemy.FindTarget(); return; } } // If no players visible, return to spawn ToReturningState(); } }