Merge commit '6ea6324be3682488352df6ad8d26ba4f69d74475' into kosmogor
This commit is contained in:
@@ -9,7 +9,6 @@ public class EyeEnemy : Enemy
|
||||
public float offsetDistance = 1f;
|
||||
|
||||
[SerializeField] float currentDelay = 0;
|
||||
|
||||
[SerializeField] Player target;
|
||||
|
||||
void Start() {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class MeleeEnemy : Enemy
|
||||
{
|
||||
public float speed = 1f;
|
||||
public float detectionRadius = 5f;
|
||||
public float patrollRadius = 3f;
|
||||
public float damage = 5f;
|
||||
public float attackRate = 1f;
|
||||
public float attackRadius = 1f;
|
||||
|
||||
[SerializeField] Player target;
|
||||
[SerializeField] MeleeEnemyState currentState = MeleeEnemyState.Patrolling;
|
||||
Vector3 patrollingTarget;
|
||||
NavMeshAgent navMeshAgent;
|
||||
|
||||
void Start() {
|
||||
target = FindFirstObjectByType<Player>();
|
||||
navMeshAgent = GetComponent<NavMeshAgent>();
|
||||
patrollingTarget = GetPatrollingTarget();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
switch (currentState) {
|
||||
case MeleeEnemyState.Patrolling:
|
||||
Vector3 vectorToTarget = (target.transform.position - transform.position).normalized;
|
||||
bool canSee = false;
|
||||
if (Physics.Raycast(transform.position, vectorToTarget, out RaycastHit hit, detectionRadius)) {
|
||||
if (hit.transform.CompareTag("Player")) canSee = true;
|
||||
}
|
||||
if (canSee) currentState = MeleeEnemyState.Pursuing;
|
||||
else {
|
||||
if (Vector3.Distance(transform.position, patrollingTarget) <= 0.1f) patrollingTarget = GetPatrollingTarget();
|
||||
navMeshAgent.destination = patrollingTarget;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 GetPatrollingTarget() {
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
enum MeleeEnemyState {
|
||||
Patrolling,
|
||||
Pursuing,
|
||||
Attacking
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53554f0e5c5ef3146a592d5dfe75e390
|
||||
Reference in New Issue
Block a user