// Update is called once per frame void Update() { if (agent.enabled) { distance = Vector3.Distance(transform.position, player.transform.position); if (distance <= aggroDistance) { agent.SetDestination(player.transform.position); animationController.EnemyMovement(); } else if (distance > aggroDistance * 1.5) { agent.SetDestination(transform.position); animationController.EnemyMovement(); } float timeSinceLastAttack = Time.time - timeOfLastAttack; bool attackOnCoolDown = timeSinceLastAttack < attack.coolDown; bool attackInRange = distance < attack.range; agent.isStopped = attackOnCoolDown; if (!attackOnCoolDown && attackInRange) { agent.velocity = Vector3.zero; animationController.EnemyAttackAnimation(); transform.LookAt(player.transform); timeOfLastAttack = Time.time; } } }
// Update is called once per frame void Update() { if (agent.enabled) { _distanceFromPlayer = Vector3.Distance(transform.position, player.transform.position); float timeSinceLastAttack = Time.time - _timeOfLastAttack; //bool attackOnCoolDown = timeSinceLastAttack < enemyStats.attackInterval; bool inRange = _distanceFromPlayer < enemyStats.attackRange; //agent.isStopped = attackOnCoolDown; if (!inRange) { agent.SetDestination(player.transform.position); Vector3 velocity = agent.velocity.normalized; float magnitude; if (velocity != Vector3.zero) { magnitude = 1; } else { magnitude = 0; } animationController.EnemyMovement(magnitude); } else { bool attackOnCoolDown = timeSinceLastAttack < enemyStats.attackInterval; if (!attackOnCoolDown) { agent.isStopped = true; agent.velocity = Vector3.zero; animationController.EnemyAttackAnimation(); transform.LookAt(player.transform); _timeOfLastAttack = Time.time; } } } }