Answer the question
In order to leave comments, you need to log in
How to get child object?
Dear prompt there is an object in it child objects.
A script is attached to the main object in which you need to work with a child object, but how to access it?
I did it like this, but I'm sure it's nonsense. If I have 900 buildings and everyone has to put down a spawn point.
I also did .Find("SpawnPoint").transform like this, but everywhere they write that Find is not the best solution to use.
Answer the question
In order to leave comments, you need to log in
Any search operations eat up resources, so yes, it's not very good to use them.
However, caching can be used for this.
That is, you find the desired object once, save a reference to it in a variable, and then use the variable.
In your case, for example, if you have 10 spawn points to which you will randomly spawn, then you can put these points in one parent container object, and manually place this container in a variable in the main script, and in the script itself in the start method write the following:
As a result, you will get the transforms of all child objects of the container.
If you do this once at the start and remember the link, then it's fine. Only one minus, if you suddenly rename. If you have over 9000 points, then hang on each component, and in the parent you will collect all the child components of this type, and then you will use this array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question