using System; using UnityEngine; using UnityEngine.AI; public class EnemyMove : MonoBehaviour { public GameObject player; [SerializeField] private float playerDetectionRadius; private NavMeshAgent _meshAgent; private bool _playerFound = false; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { _meshAgent = GetComponent(); } // Update is called once per frame void Update() { Vector3 playerPos = player.transform.position; Debug.DrawRay(transform.position, (playerPos - transform.position).normalized * playerDetectionRadius, Color.red); if (!_playerFound && Physics.Raycast(transform.position, (playerPos - transform.position).normalized, out RaycastHit hit, playerDetectionRadius)) { _playerFound = hit.collider.name == player.name; } if (_playerFound) { _meshAgent.SetDestination(playerPos); } _meshAgent. } }