GetComponent 是访问游戏对象的组件并调整参数的方法,
GetComponentInChildren是获取子物体的组件。
一、GameObject.GetComponent
GetComponent是获取当前游戏对象组件的方法,可以通过直接调用它来访问游戏对象的组件和进行参数调整。
1.格式用途
GameObject.GetComponent<type>()
(1)GameObject 是定义 GameObject 游戏对象的变量名。
(2)type 是组件名称,类型是 string。
2.举例说明
1.GetComponent<Rigidbody>().mass = 20;
表示 Rigidbody 组件的 mass 赋值为20;
GetComponent<Rigidb