update scripts
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user