OldBlueWater/BlueWater/Assets/02.Scripts/Ai/AiMover.cs
2023-08-08 16:53:35 +09:00

62 lines
1.6 KiB
C#

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<AiController>(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
}
}