Hello all, novice question for you.
Im making a small pizza delivery game. Currently trying to get a Delivery Waypoint system in order.
Someone earlier showed me the list function and I figured its perfect for what Id like to happen.
The way I envision it is there are all the vector3 positions preselected on the map. I need one of them to fire off as the currentMarker and have the Gameobject I selected in the inspector (Red Waypoint Box) to be moved to the new currentMarker. Ive looked and searched but cant seem to write it in a way that unity understands whats the hell I want from it. Here is the script Im working with. Thanks in advance.
public class PositionFinder : MonoBehaviour
{
//Hold a list of all possible positions
public List markerPositions = new List();
public GameObject Waypoint;
//The active marker we are chasing
public Vector3 currentMarker = Vector3.zero;
//Call this function to start or when the user reaches a marker
public void OnMarkerComplete()
{
HELP HERE // Waypoint.transform.position = new Vector3.currentMarker;
//If we have markers remaining in our list we can find a new one
if (markerPositions.Count > 0)
{
//pick a random index between min and max index
int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);
//Assign the random marker we found as the active one
currentMarker = markerPositions[randomIndex];
//Remove the marker we are using from the list
markerPositions.RemoveAt(randomIndex);
}
}
}
Try something like this :
public List<Vector3> markerPositions = new List<Vector3>();
public GameObject waypoint;
public Vector3 currentMarker = new Vector3();
public void OnMarkerComplete()
{
//If we have markers remaining in our list we can find a new one
if (markerPositions.Count > 0)
{
//pick a random index between min and max index
int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);
//Assign the random marker we found as the active one
currentMarker = markerPositions[randomIndex];
// set the waypoint to the randomly selected marker's position
waypoint.transform.position = currentMarker;
//Remove the marker we are using from the list
markerPositions.RemoveAt(randomIndex);
}
}
public class PositionFinder : MonoBehaviour
{
//Hold a list of all possible positions - public makes it show in the inspector so your can set them there
public List markerPositions = new List();
// markerPositions.Add(new Vector3(48f,-3f,31f));
public GameObject Waypoint;
public Vector3 currentMarker = new Vector3();
public void OnMarkerComplete()
{
//If we have markers remaining in our list we can find a new one
if (markerPositions.Count > 0)
{
//pick a random index between min and max index
int randomIndex = UnityEngine.Random.Range(0, markerPositions.Count - 1);
//Assign the random marker we found as the active one
currentMarker = markerPositions[randomIndex];
// set the waypoint to the randomly selected marker's position
Waypoint.transform.position = currentMarker;
//Remove the marker we are using from the list
markerPositions.RemoveAt(randomIndex);
}
}
}
This is with the “changes” you’ve suggested to make.