function GetComponentInChildren (t : 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类型组件,在GameObject或它的任何子物体使用深度优先搜索,仅返回激活的组件。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public ScriptName script;
public void Awake() {
script = GetComponentInChildren<ScriptName>();
script.DoSomething();
}
}
var script : ScriptName;
script = GetComponentInChildren(ScriptName);
script.DoSomething ();