- Home /
How to access objects attached to other objects
I attached a plane(like a flat piece of ground) to another object and want to know how I can setActive(false) or (true) the plane attached to this object. Is this called the child of an object?
Here is an image for reference
http://tinypic.com/r/2co6amw/8
I am trying to access "Plane" attached to "Unit1" as seen in the image above
Thanks for your help!
Answer by QuestionAsker · Jul 03, 2014 at 03:32 AM
If you have a script on Unit1 use the following line:
GameObject plane = transform.FindChild("Plane");
Then to setActive, I believe this will work:
plane.setActive(false); //or true
Let me know how it goes!
I editted my answer! Sorry about that. Forgot about the second part to you post.
@QuestionAsker Does not work. Returns cannot convert from transform to gameobject. I looked it up and it says that it returns a transform, which is fine, but you cannot use setactive() on a transform. $$anonymous$$now any solution? Thanks,
@QuestionAsker You were right, except missing one bit onto your code. It should be this:
GameObject plane = transform.FindChild("Plane").gameObject;
Thanks for your help man, you were a big help in me solving this. I knew it was a small line of code to do this, but it was difficult to find information about child objects... :)