Doubts about foreach Logic in the EnemyMover script in the 3D course Lesson 129

On the FindPath Method it says


and what i want you to focus on is on the foreach(Transform tile in Tiles.transform) why use that instead of foreach(Gameobject tile in Tiles), i just cant seem to grasp the logic no matter how much i think about it.

Hi,

Welcome to our community! :slight_smile:

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

The information on the children is stored in the Transform object, not in the GameObject object. The returned children are of type Transform, just like the parent. That does not have anything to do with logic. That is just how the Unity programmer defined the parent-child relationship.

Hope this helps :slight_smile:


See also;

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

Privacy & Terms