This commit is contained in:
Andrey Gumirov
2022-04-18 19:01:06 +07:00
parent e1d0bbc1eb
commit 4bd1e0644a
8 changed files with 54 additions and 22 deletions

View File

@ -7,13 +7,28 @@ using UnityEngine.AI;
public class MovementController : MonoBehaviour
{
public NavPoint currentPosition { get; set; }
private Dictionary<int, NavPoint> navPoints = new Dictionary<int, NavPoint>();
[SerializeField] private NavMeshAgent navMeshAgent;
private void Start()
{
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
foreach (var np in MapManager.navPoints) {
navPoints[np.PointId] = np;
}
}
public void MoveToPointById(int id)
{
if (!navPoints.ContainsKey(id))
{
Debug.LogWarning("PIDOR");
return;
}
goToNextNavPoint(navPoints[id]);
}
public void MoveToRandomPoint()
{
Debug.Log(MapManager.navPoints == null);
@ -23,7 +38,7 @@ public class MovementController : MonoBehaviour
public List<NavPoint> getPointsCandidate()
{
return MapManager.navPoints
.Where(point => (currentPosition.position - point.position).magnitude < SettingsReader.Instance.GetSettings.movementSpeed)
.Where(point => (currentPosition.position - point.position).magnitude < SettingsReader.Instance.GetSettings.movementDistance)
.ToList();
}