I’m a bit unclear why when you use transform inside a foreach loop you get the children transforms. For example if you use transform somewhere else and set a different position then it will use the transform of the root object where the script is, but when used in foreach it returns all the transforms of the children of the root object?
A transform is ‘enumerable’. That is, it implements the IEnumerable
interface. The implementation in a transform return the transforms of the children. This is why we can foreach
over a transform to get the children.
It is similar to a list (which is also ‘enumerable’). We can Add, Remove, etc. on a list, but when we foreach
over it, we get the items contained within that list.
Basically, a transform is a transform, but it is also a list of child transforms
Thanks for the detailed answer!
My pleasure. It took a few edits before it was that detailed
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.