- Home /
Store information of distination to use in next script
Hello everybody,
The question is: how can I store the int information to be used farther in a script?
and here's the line of code I use:
public int nextWayPoint;
public void Patrol()
{
shopper.navMeshAgent.destination = SceneIndex.instance.waypoints[nextWayPoint].position;
}
[nextwayPoint] is an int.
I would like to make a transfrom varibale like "currentwayPoint" and say currentwayPoint = nextwayPoint. like: SceneIndex.instance.waypoints[currentwayPoint].position
But I can't because it has to be something associated with ints...
EDIT PHOTOS ADDED:
What you are saying makes no sense, can you further elaborate?
Yes of course. I have an array of way points. the ai is going from one to another.
nextWayPoint = (nextWayPoint + 1) % SceneIndex.instance.waypointTransforms.Length;
this is the line for patroling. this is the line for setting the destination:
shopper.nav$$anonymous$$eshAgent.destination = SceneIndex.instance.waypointTransforms[nextWayPoint].targetTransform.position;
At this moment , is it correct to say that the AI is going to a specific destination, and what going to define that destination is the int within the square brackets [nextwayPoint]?
If so, is it posible that farther in the code if I want to adress this destination I should be able to do so?
Answer by fvde · Jul 11, 2017 at 11:30 AM
@Eco-Editor nextwayPoint
is an Integer which cannot hold a reference to a Vector3. I would suggest you store the Transform as the next waypoint, like this:
Transform nextwayPoint = SceneIndex.instance.waypoints[currentwayPoint]
Then you can use it moving forward like this:
nextwayPoint.position
Answer by Eco-Editor · Jul 12, 2017 at 08:01 PM
@fvde hi, Im no expert but I think the whole idea of having "nextWayPoint" as an integer is because of the function that uses % sign for deciding what point is next.
wayPoint = (nextWayPoint + 1) % points.Length;
}
How else would you reference the next wayPoint?
Why don't you ins$$anonymous$$d do something like this:
public int currentWayPoint = 0;
public int nextWayPoint
{
get
{
currentWayPoint = (currentWayPoint + 1) % points.Length;
return currentWayPoint;
}
}
that way you can use currentWayPoint further down in your script, and everytime you need a new waypoint you can just use nextWayPoint and it will update the current waypoint aswel.
Hello @ShadyProductions and all,
Perhaps a picture is worth a thousand words: In the picture (above) you can see my wayPoints on the ground. Each has a blue local arrow pointing to the shelf, e.g, Point 1 is pointing downwards, whereas point 3 is pointing upwards (in this photo), and an avatar supposed to face the shelf, using transform. forward.
In the second photo (above), you see how my destination point is different from turning point. If you look at the three button lines, the avatar is at point 4 (it is in the photo), but is facing the turning point, point 3 (also in the photo).
Why is that happening?
You can see that it's actually going backwards: destination is 2-> turning to 1,destination is 3-> turning to 2,destination is 4-> turning to 3 This is why I wanted to store the integer so it doesn't need to call the function again using: currentWayPoint = **(currentWayPoint + 1)** % points.Length;
Your answer
Follow this Question
Related Questions
Cannot convert 'callable(int) as float' to 'float'. 1 Answer
Object to int 1 Answer
c# convert int to string 2 Answers
Having a GUI text as a int 3 Answers