Unity常用API理解

xiaoxiao2021-02-28  233

GameObject相关

一.游戏物体创建

1.通过new方法直接创建

new GameObject();//创建出一个空物体

2.通过Instantiate方法创建

//类似与复制一个gameObject GameObject.Instantiate(GameObject gameObjct);

3.通过CreatPrimitive方法创建

//创建出比较原始的primitive物体 GameObject.CreatPrimitive(Primitive primitive);

二.常用属性 1.activeInhierarchy(bool类型)

//更改该属性即更改游戏物体的激活状态 gameObject.SetActive(bool active);

2.tag(string类型) 就是游戏物体的标签,没啥好讲的

三.独有的静态方法 1.Find( )方法

GameObject.Find(string name);

2.FindObjectWithTag( )方法

GameObject.FindObjectWithTag(srting tag);

四.继承的静态方法 GameObject类继承自Objct类,因此具备有Object类中的一些静态方法。 1.Destroy( )方法

Destroy(GameObject gameObject);

五.公有方法

ps:以下公有方法在Component类和MonoBehaviour类中也存在,对组件和脚本进行以下这些操作相当于对组件所在的游戏物体进行操作

1.SendMessage()方法

//调用该游戏物体上所有脚本中的指定方法 gameObject.SendMessage(string function);

2.BroadcastMessage()方法

//调用该游戏物体和其所有子物体上脚本中的指定方法 gameObject.BroadcastMessage(string function);

3.SendMessageUpwards()方法

//调用该游戏物体和其父级(包括父级以上)物体上脚本中的指定方法 gameObject.SendMessageUpwards(string function);

4.GetComponent()方法

5.GetComponentInChildren()方法

6.GetComponentInParent()方法

4,5,6 方法是得到某游戏物体上某一组件的应用 当把Component改做Components变为得到多个组件的引用

转载请注明原文地址: https://www.6miu.com/read-18215.html

最新回复(0)