[SOLVED] Using a field of every object of a list.

In my game, I have this function:

target = Targeting.GetClosestObject (Globals.allCasters, transform);target = Targeting.GetClosestObject (Globals.allCasters, transform);

The problem is I just remembered that “Globals.allCasters” is a GameObject list.
I’d like to do something like this:

“Globals.allCasters.transform”

(yes, I know I could create a new list and add the transforms by enumerating through the GameObject list but I’m wondering if there’s an easier way.)

Rewrite GetClosestObject.
Since it’s called OBJECT id expect it to take GOs
keep a copy of it as it is now, and call it GetClosestTransform. idk

1 Like

We don’t know what ‘GetClosestObject’ expects as a paremeter. This method is not defined for us.

If you want to take a collection of objects, and get a new enumerable collection of objects that are fields of the objects in the first collection. Try linq:

var allCastersTransforms = (from go in Globals.allCasters select go.transform);

You need to import ‘System.Linq’.

1 Like

Yeah I ended up renaming it. That was dumb of me to make it take transforms.
Thanks to lordofduct’s solution though. It’ll come up handy in the future.