Files
real-shooter/Assets/Scripts/Character/MovementController.cs
2022-04-18 09:34:08 +07:00

33 lines
1022 B
C#
Executable File

using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class MovementController : MonoBehaviour
{
public NavPoint currentPosition { get; private set; }
[SerializeField] private NavMeshAgent navMeshAgent;
private void Start()
{
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
}
public void MoveToRandomPoint()
{
Debug.Log(MapManager.navPoints == null);
goToNextNavPoint(MapManager.navPoints[Random.Range(0, MapManager.navPoints.Count)]);
}
public List<NavPoint> getPointsCandidate()
{
return MapManager.navPoints
.Where(point => (currentPosition.position - point.position).magnitude <= SettingsReader.Instance.GetSettings.movementSpeed)
.ToList();
}
public void goToNextNavPoint(NavPoint destination) =>
navMeshAgent.SetDestination(destination.position);
}