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 (!GetTargetInfo().transform || moveType is MoveType.NONE or MoveType.FIXED) return; GetNavMeshAgent().SetDestination(GetTargetInfo().transform.position); } } #endregion #region Custom function public void MoveTarget(Vector3 targetPos) { isCommanded = true; GetNavMeshAgent().SetDestination(targetPos); } public bool GetIsCommanded() => isCommanded; private TargetInfo GetTargetInfo() => aiController.TargetInfo; private NavMeshAgent GetNavMeshAgent() => aiController.GetNavMeshAgent(); #endregion } }