foreach(Transform weapon in transform)

Hello,
I am a bit confused, why does a foreach loop only iterate through only the child object’s transforms?
Does the loop also include the parent’s transform?

Hi Sung-jin,

The foreach-loop iterates over the children only. Maybe the original code is a bit cryptic. Here is a “translation”:

Transform parent = transform;

foreach (Transform child in parent) { }

Bear in mind that this is a special feature of the Transform class. This does not work with all C# classes.

Is this what you wanted to know?


See also:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms