using System.Collections;
using System.Collections.Generic;
[RequireComponent(typeof(NavMeshAgent))]
public class Enemy : Character
protected Transform player;
protected NavMeshAgent agent;
[Header("System Attack")]
[SerializeField] protected float agroRange;
[SerializeField] protected bool meleeAttack;
[SerializeField] protected bool rangedAttack;
protected float distanceToPlayer;
[Header("Attack System - Melee")]
[SerializeField] protected float meleeAttackDamage;
[SerializeField] protected float meleeAttackRate;
[SerializeField] protected float meleeAttackRange;
protected float meleeAttackTime = 0f;
[Header("Attack System - Ranged")]
[SerializeField] protected float rangedAttackDamage;
[SerializeField] protected float rangedAttackRate;
[SerializeField] protected float rangedAttackRange;
protected float rangedAttackTime = 0f;
protected override void Awake()
player = GameObject.FindGameObjectWithTag("Player").transform;
agent = GetComponent<NavMeshAgent>();
protected override void Update()
protected virtual void EnemyAI()
distanceToPlayer = Vector3.Distance(transform.position, player.position);
if (distanceToPlayer <= agroRange)
if(meleeAttack || rangedAttack)
protected virtual void Attack()
if (distanceToPlayer <= meleeAttackRange && meleeAttack)
else if (distanceToPlayer <= rangedAttackRange && rangedAttack)
protected virtual void MeleeAttack()
agent.SetDestination(transform.position);
if(Time.time >= meleeAttackTime)
meleeAttackTime = Time.time + (1f / meleeAttackRate);
Debug.Log("MeleeAttack");
protected virtual void RangedAttack()
agent.SetDestination(transform.position);
if (Time.time >= rangedAttackTime)
rangedAttackTime = Time.time + (1f / rangedAttackRate);
Debug.Log("RangedAttack");
protected virtual void Follow()
agent.SetDestination(player.position);
protected virtual void IdleAction()
agent.SetDestination(transform.position);