x


How to get all child objects~!

thankyou!!

125alt text125

var cube :GameObject;

function OnGUI () {

if(GUI.Button(Rect(0,0,100,20),"OK"))
{
    for(GameObject in cube){
       print("OK");
       cube.gameObject.renderer.material.color=Color.blue;

    }
}

}

more ▼

asked Aug 19 '11 at 06:36 AM

xiaohe gravatar image

xiaohe
11 8 10 12

yes.

Aug 19 '11 at 06:37 AM testure
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Use GetComponenetsInChildren

Here is an example of how to use it:

function getTransformsOfChildren(target : GameObject) : Transform[]
{    return target.GetComponentsInChildren.<Transform>();    }

A transform is just the easiest and most reliable way to do this because each object has exactly one transform.

more ▼

answered Aug 19 '11 at 04:06 PM

SilverTabby gravatar image

SilverTabby
2.2k 3 7 23

(comments are locked)
10|3000 characters needed characters left

Hi, In this function :

function GetMeshRendererOfChildren(target : GameObject) : MeshRenderer[]

{    return target.GetComponentsInChildren.<MeshRenderer>();    }

how Can I Access the newly made Array ? Will it be at GetMeshRendererOfChildren[i] ?

more ▼

answered Oct 16 '11 at 11:12 AM

eXo gravatar image

eXo
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5390

asked: Aug 19 '11 at 06:36 AM

Seen: 1784 times

Last Updated: Oct 16 '11 at 11:12 AM