- Home /
Make object move through waypoints by the given number in the name
Hi! If I use some Gameobjects with the names GameObject1, GameObject2, GameObject3 and so on as waypoints, is there a possibility to tell the Object that's folloing these waypoints to do so by the given name? So it will go first to the GameObject1, then GameObject2, then GameObject3 etc. I know, I could bring the Objects in a right order into a list. I tried this and it didn't work out as I wanted it to, because it should delete the object and the index entry in the list, as soon as the object passed this waypoint. So I'd like to try it with making the Object move through the waypoints by the given name, no matter on which index they stand in the list. Is that possible? Thanks a lot!
Answer by DaveA · Sep 03, 2013 at 10:56 PM
I don't know why you'd have to destroy waypoints, cuz that's the easiest way to do it, but if you must then just do something like this:
var nextWaypointName = "GameObject" + i;
var nextWaypoint = Transform.Find(nextWaypointName);
where i is an integer you increment. You increment it when the object reaches the waypoint and it's up to you how to detect that (like using Update and Lerp to move, and a close-enough proximity distance to say 'it's gotten there)