- Home /
GetComponentInChildren is getting Sibling s Child
I have a folder hierarchy like below. 'Circle's are drawing the circles, and 'OuterCircle & InnerCircle' have instantiating and narrowing scripts.
MainParent
- OuterCircle (instantiate + narrow)
- Circle (draw)
- InnerCircle
- Circle
Instantiating is working perfect for each one and when instantiating, it destroys the old one and instantiate new one with the same name.
In the first go (destroying + initialising), narrowing script works as expected. But after initiating new circle gameobjects, it is grabbing one gameObject at a time.
If the narrowing script is running in OuterCircle
and InnerCircle
gameObject (parents), shouldn't GetComponentInChildren work independently so they behave for their own child rather than grabbing each others. Because I think the problem is both folder starts grabbing other parent's child.
public BuildCircleMesh circleScript;
void Start () {
circleScript = gameObject.GetComponentInChildren<BuildCircleMesh> ();
}
void Update () {
if (circleScript == null) {
circleScript = GameObject.Find("GameCircle").GetComponentInChildren<BuildCircleMesh>();
}
circleScript.innerRadius = circleScript.innerRadius - 5 * Time.deltaTime;
}
Your answer
Follow this Question
Related Questions
Find GameObjects with a true boolean and put them in an array? 1 Answer
Is "GameObject.FindAllGameObjectsWithTag" related to the hierachy? 1 Answer
Distribute terrain in zones 3 Answers
GameObject.Find, When it is Called? 1 Answer
How do I retrieve deep levels of nested child transforms with a generic snippet of code 2 Answers