public Vector3 GetCurrentWaypoint(Vector3 position) { //CORREGI ESTO!!!!!!!!!!!!!!!!!!!!!! if (_path == null) { return(Vector3.zero); } float distance = Vector3.Distance(position, _path[_targetIndex]); if (distance > .5f) { return(_path[_targetIndex]); } _targetIndex++; if (_targetIndex < _path.Length) { return(_path[_targetIndex]); } _path = null; // When it reaches it's target, it unsuscribe from the grid update. PathRequestManager.RemoveFromChange(SuscriptionToChange); return(Vector3.zero); }
/// <summary>Move to the waypoint, when close enough switchs to the next waypoint</summary> private void MoveThroughPath(ref Vector3 currentWaypoint) { float distance = Vector3.Distance(transform.position, currentWaypoint); if (distance < .5f) { _targetIndex++; if (_targetIndex >= _path.Length) { _path = null; // When it reaches it's target, it unsuscribe from the grid update. PathRequestManager.RemoveFromChange(SuscriptionToChange); return; } currentWaypoint = _path[_targetIndex]; } MoveTo(currentWaypoint); }