I start by checking if the “Targets” list has something inside of it. Then for each gameobject inside of the list, I sort the objects by distance to the center of the screen.
However… when I load up the game and check in the inspector. The elements don’t change their order based on this. Do you mind if I have any assistance on this?
If you Debug.Log out each element in the Targets collection, do they appear in the correct or incorrect order?
I think I’ve had this issue before. The elements in memory have been updated, but the serialised data (which is what the inspector reads from and displays) hasn’t been updated to match.
Ouhh, this is far off Like herrmutig already said, OrderBy does already sort the collection based on the selection method you provide and returns a new collection that is sorted. So iterating through the list while you sort the whole list again and again doesn’t make much sense.
Furthermore your selection method also does not make any sense. It returns the same value regardless of the current element. You just calculate the distance from the SpawnPoint object to the viewport point “0.5f, 0.5f, 0.1f”. You do that for every object in the collection. The “x” variable inside the selection method represents the current object in the collection. This method should return a value on which the collection should be sorted. So for example the distance of x from your SpawnPoint? Or something like that. Depending on your type of game, the distance from the world position of the camera center may not really represent what you think it would. However if that’s really want you want to do, you should do
Thank you! Both of you helped me. I’m still overall very new to C# and of course when I lay in bed and start thinking about my code I immediately figured it out as well.