Im making a RTS game with resource collecting units, when they are full they are put into a list so only one truck gets to move on the drive thru resource droppoff ramp at once. I have an idea on how to start this but need some help, I’m wondering how I can do two things, Make the truck find the nearest droppoff point using tags and vector3.distance and how can I make a list sort trucks based on how close they are to the building so the closest truck can droppoff instead of waiting forever for another dumptruck far away to get there. Also when moving the trucks to the resource depot and on the ramp is it best to make invisible gameobjects they have to move to or is there a more convenient way? Thanks!!
It’s not the full answer but it’s a little help with the logic of your code.
When you say “find the nearest dropoff” You’re only looking for one with the tag:
First, dont “Find” gameObject (I’m talking about ‘FindGameObjectWithTag’. Or do it the least as possible. Never do it in Update. Awfull for game performance.
You should have a list of all your ‘RessourceDepot’ somewhere and call that to find the closest one. To find the closest object check this post. Just again, limit the “Find” methods.
For your ressource depot location, best would be to have a list of Vector3 with those locations that could be set from the start (before the Start ). They dont have to be gameObjects at all, but if you do use them as gameObjects, they can be empty GameObjects