using System; using UnityEngine; using UnityEngine.AI; // ReSharper disable once CheckNamespace namespace BlueWaterProject { public class AiMover : MonoBehaviour { private enum MoveType { NONE, // 미설정 FIXED, // 자리를 지키는 AI MOVE // 자리를 움직이는 AI } #region Property and variable [SerializeField] private MoveType moveType; private bool isCommanded; private Vector3 movePos; private AiController aiController; #endregion #region Unity built-in function private void Awake() { aiController = Utils.GetComponentAndAssert(transform); } private void LateUpdate() { aiController.GetAnimator().SetFloat(AiController.SpeedHash, aiController.GetNavMeshAgent().velocity.normalized.magnitude); if (isCommanded || aiController.GetIsAttacking()) { } else { if (!GetTarget() || moveType is MoveType.NONE or MoveType.FIXED) return; GetNavMeshAgent().SetDestination(GetTarget().position); } } #endregion #region Custom function public bool GetIsCommanded() => isCommanded; private Transform GetTarget() => aiController.GetFieldOfView().GetTargetTransform(); private NavMeshAgent GetNavMeshAgent() => aiController.GetNavMeshAgent(); #endregion } }