Access TMPro-Text after instantiating instead of creating GridDebugObject

Hey Team! Great work btw, love the content!

I always try to do the next steps on my own and see if the course leads the same way… So far so good.

Now, regarding the DebugGridObject, I just set the text of the TMPro-Text after instantiating GridDebugObject-Prefab.

Transform debugObject = GameObject.Instantiate(debugPrefab, GetWorldPosition(gridPosition),Quaternion.identity);
debugObject.GetComponentInChildren<TextMeshPro>().text = "X: " + x + "\n" + "Z: " + z;

So yeah, this works, but Hugo created the GridDebugObject class and handled it that way, which seemed a little overkill to me (I mean not really, its 4 lines code more :stuck_out_tongue: )

So, long story short, are we going to do more in the future with this class, do I need it, or can I just leave it as is? Or is there any notes to my method e.g. bad coding?

Thats it! Thanks again for this awesome learning content, loved the courses on udemy already, but here with a forum its even better! Hope I find the time to really engage with the community.

Regards and thanks in advance,

Alex

The GridDebugObject is exactly that, just an object that will show the x-z coordinates. In fact, when you build the game out to be played by others, it’s best if you don’t show the GridDebugObjects at all (the players shouldn’t be worried about coordinates).

I think your setup is fine.

1 Like

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

Privacy & Terms