格式
typescript
GameObject.GetComponents(type)所属类: GameObject
描述
返回 GameObject 中类型为 type 的所有组件。
参数
| 参数名 | 类型 | 描述 |
|---|---|---|
| type | Component | 组件类型 |
返回值
| 类型 | 描述 |
|---|---|
T|null | 返回包含该类型的组件的数组,如果没有该类型的组件,则返回null |
代码示例
typescript
let go = new GameObject();
//获取游戏对象或游戏对象的任何子级上的BoxCollider组件
let box = go.GetComponents(BoxCollider);
if(box){
Debug.Log(box);
}else{
Debug.Log("未找到组件");
}