files add
This commit is contained in:
@ -9,27 +9,28 @@ public class MovementController : MonoBehaviour
|
||||
public int PointStartID { get; set; }
|
||||
public int PointEndID { get; private set; }
|
||||
public float FlagDistance { get; private set; }
|
||||
private const float updateFlagPositionDelay = 5;
|
||||
private const float updateReachedDestinationDelay = 5;
|
||||
private const float UpdateFlagPositionDelay = 5;
|
||||
private const float UpdateReachedDestinationDelay = 5;
|
||||
|
||||
[SerializeField] private NavMeshAgent navMeshAgent;
|
||||
[SerializeField] private GameObject flag;
|
||||
public float DistanceToGo { get; private set; }
|
||||
public float RemainingDistance => navMeshAgent.remainingDistance;
|
||||
private Dictionary<int, NavPoint> idNavPointDict;
|
||||
private Dictionary<int, NavPoint> _idNavPointDict;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
navMeshAgent.speed = SettingsReader.Instance.GetSettings.MovementSpeed;
|
||||
idNavPointDict = MapManager.IDToNavPoint;
|
||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, updateFlagPositionDelay);
|
||||
InvokeRepeating(nameof(ReachedDestination), 0, updateReachedDestinationDelay);
|
||||
_idNavPointDict = MapManager.Instance.IDToNavPoint;
|
||||
InvokeRepeating(nameof(UpdateFlagPosition), 0, UpdateFlagPositionDelay);
|
||||
InvokeRepeating(nameof(ReachedDestination), 0, UpdateReachedDestinationDelay);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CancelInvoke(nameof(UpdateFlagPosition));
|
||||
CancelInvoke(nameof(ReachedDestination));
|
||||
}
|
||||
|
||||
private void UpdateFlagPosition()
|
||||
@ -39,14 +40,14 @@ public class MovementController : MonoBehaviour
|
||||
|
||||
public void MoveToRandomPoint()
|
||||
{
|
||||
GoToNextNavPoint(MapManager.NavPoints[Random.Range(0, MapManager.NavPoints.Count)]);
|
||||
GoToNextNavPoint(MapManager.Instance.NavPoints[Random.Range(0, MapManager.Instance.NavPoints.Count)]);
|
||||
}
|
||||
|
||||
public List<NavPoint> GetPointsCandidate()
|
||||
{
|
||||
return MapManager.NavPoints
|
||||
return MapManager.Instance.NavPoints
|
||||
.Where(point =>
|
||||
(idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
(_idNavPointDict[PointStartID].Position - point.Position).magnitude < SettingsReader.Instance.GetSettings.MovementDistance)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ public class MovementController : MonoBehaviour
|
||||
public void ReturnToStartPoint()
|
||||
{
|
||||
if (navMeshAgent.isStopped == true) navMeshAgent.isStopped = false;
|
||||
navMeshAgent.SetDestination(idNavPointDict[PointStartID].Position);
|
||||
navMeshAgent.SetDestination(_idNavPointDict[PointStartID].Position);
|
||||
PointEndID = PointStartID;
|
||||
PointStartID = -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user