H
H
Hixac2020-12-17 16:08:27
Unity
Hixac, 2020-12-17 16:08:27

How to get component with child GameObject?

5fdb57928bd00282179752.png
There is such a hierarchy, I need to get the TextMesh component with the HP amount and Damage amount and use it, I don’t know how to do it in the best way and is it worth it at all? Data must be obtained from a click.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2020-12-17
@Hixac

bad way

var hpTextTransform = transform.Find("HP Image/HP Amount");

In my mind, the main prefab has a serialized variable into which you transferred the component you need through the inspector. This will save you from renaming objects or changing their location.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question