GameObject类

来源:互联网 发布:vivo的软件商店 编辑:程序博客网 时间:2024/06/05 15:44

GameObject类是Unity场景中所有实体的基类。GameObject是许多不同组件的容器,默认所有游戏对象都会自动拥有一个transform组件。

常用方法总结:

1、创建一个新的游戏对象:

public GameObject();

public GameObject(string name);

public GameObject(string name,params Type[] component);

2、向游戏对象添加此类型的组件:

public Component AddComponent(Type componentType);

3、判断该游戏对象的标签是否是tag:

public bool CompareTag(string tag);

4、获取游戏对象中拥有此类型的组件:

public Component GetComponent(Type type);

5、获取一个被标签标记的激活的游戏对象:

public static GameObject[] FindGameObjectWithTag(string tag);

6、获取一个被标签标记的活动的游戏对象列表:

public static GameObject[] FindGameObjectsWithTag(string tag);

注:若标签不存在,则抛出一个UnityException。

7、返回游戏对象的名称:

public string ToString();

8、删除一个游戏对象、组件或资产:

public static void Destory(Object obj,float t);

9、立即销毁对象:

public static void DestoryImmediate(Object obj,bool allowDestoryingAssets=false);

10、生成对象实例:

public static Object Instantiate(Object original,Vector3 position,Quaternion rotation);

原创粉丝点击