API:应用程序编程接口


1,创建物体的三种方法:

//1,第一种创建方法//GameObject go是得到返回值。

GameObject go=new GameObject(“Cube”);

//2,第二种

//根据prefab,实例化。根据模板或者另外一种方式进行克隆。

GameObject.Instantiate(prefab);

//第三种:primatetype,可以创建一些基本的物体。

GameObject.CreatePrimitive(primatetype.Plane);

GameObject.CreatePrimitive(primatetype.Cube);


2,如何给游戏物体通过代码添加组件

GameObject go(得到返回值)=GameObject.CreatePrimitive(PrimitiveType.Plane);

go.AddComponent<rigidbody>();

go.AddComponent<所要选择的组件>();


3,如何禁用和启用一个物体

activeinHierarchy:判断是否为**状态,禁用物体其子物体也被禁用。

禁用后各种属性依然是可以获得的。一般不需要的的都设置为flase,可以节约性能。

Debug.Log(go.activeinHierarchy)           //是一个bool值。

go.SetActive (flalse);          


4,GameObject,Component和object 的关系


GameObject是物体,Component 是组件,object是物体

Unity系列(三)




相关文章:

  • 2021-08-02
  • 2021-08-07
  • 2021-04-15
  • 2021-10-22
  • 2021-07-11
  • 2022-01-06
  • 2021-05-30
  • 2021-07-16
猜你喜欢
  • 2022-01-02
  • 2021-04-30
  • 2021-12-17
  • 2022-12-23
  • 2021-07-17
  • 2021-10-29
  • 2021-07-06
相关资源
相似解决方案