function GetComponentInChildren (type : Type) : Component
Description描述
Returns the component of Type type in the GameObject or any of its children using depth first search.
Only active components are returned
返回这个游戏物体或者它的所有子物体上(深度优先)的类型为type的组件。
只返回活动的组件。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public ScriptName script;
public void Awake() {
script = gameObject.GetComponentInChildren<ScriptName>();
script.DoSomething();
}
}
var script : ScriptName;
script = gameObject.GetComponentInChildren(ScriptName);
script.DoSomething ();