41 lines
1.3 KiB
C#
Executable File
41 lines
1.3 KiB
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 Move()
|
|
{
|
|
var pointCandidate = getPointCandidate();
|
|
goToNextNavPoint(pointCandidate);
|
|
}
|
|
|
|
public void MoveToRandomPoint()
|
|
{
|
|
Debug.Log(MapManager.navPoints == null);
|
|
goToNextNavPoint(MapManager.navPoints[Random.Range(0, MapManager.navPoints.Count)]);
|
|
}
|
|
|
|
private NavPoint getPointCandidate() // todo тут нужно, чтобы выдавался массив точек
|
|
{
|
|
var NavPointsPositions = MapManager.navPoints
|
|
.Select(point => point.transform.position)
|
|
.Where(point => (currentPosition.transform.position - point).magnitude <= SettingsReader.Instance.GetSettings.movementSpeed)
|
|
.ToList();
|
|
return null;
|
|
}
|
|
|
|
public void goToNextNavPoint(NavPoint destination) =>
|
|
navMeshAgent.SetDestination(destination.transform.position);
|
|
}
|