Unity3d get all Sub object Objects (child) of an object

Source: Internet
Author: User
began to find the next u3d script book, found that this thing can not find. Then Google search "Unity3d get all child" only to find the answer. Very simple answer, but very interesting, very useful.
foreach (Transform child in Transform) { Debug.Log (child.gameObject.name);}
Transform is the transform of the object gameobject you need to find. The For loop is the equivalent of traversing its sub-object, and all you have to do is put it in the array. If you want to filter out some of the sub-objects in the loop to write a bit is OK.
Delete all child objects:
foreach (Transform child in Transform) { Destroy (child.gameobject);}
Forget when, it is not possible to delete this, but now it is possible.
2014.1.3 added: The way to traverse the delete seems to be not possible, or to store it in a list to delete one after another. It seems that some circumstances can be not, very strange.
Transferred from: http://www.360doc.com/content/16/0531/23/33879684_564041693.shtml

Unity3d get all Sub object Objects (child) of an object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.