update scripts

This commit is contained in:
2022-04-25 16:23:25 +07:00
parent e1d0bbc1eb
commit 290f5515b7
13 changed files with 120 additions and 47 deletions

View File

@ -2,16 +2,31 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using System.Threading.Tasks;
[RequireComponent(typeof(NavMeshAgent))]
public class MovementController : MonoBehaviour
{
public NavPoint currentPosition { get; set; }
public NavPoint CurrentNavPoint { get; set; }
public float FlagDistance { get; private set; }
private GameObject flag;
private const float updateFlagPositionDelay = 5;
[SerializeField] private NavMeshAgent navMeshAgent;
private void Start()
{
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
}
private void OnDestroy()
{
CancelInvoke(nameof(UpdateFlagPosition));
}
private void UpdateFlagPosition()
{
FlagDistance = (flag.transform.position - gameObject.transform.position).magnitude;
}
public void MoveToRandomPoint()
@ -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 => (CurrentNavPoint.position - point.position).magnitude < SettingsReader.Instance.GetSettings.MovementSpeed)
.ToList();
}