GameObject 游戏对象
Unity场景里面所有实体的基类
GameObject.activeInHierarchy 在层级激活
场景中的游戏对象是否激活
bool activeInHierarchy;
GameObject.activeSelf 激活自己
该游戏对象的局部激活状态
bool activeSelf;
GameObject.AddComponent 添加组件
添加一个名称为className的组件到游戏对象
public SphereCollider sc; void Example() { sc = gameObject.AddComponent("SphereCollider") as SphereCollider; }
GameObject.animation 动画
附加于这个游戏对象上的动画
public GameObject other; void Example() { other.animation.Play(); }
GameObject.audio 音频
附加于这个游戏对象上的音频资源
public GameObject other; void Example() { other.audio.Play(); }
GameObject.BroadcastMessage 广播消息
对此游戏对象及其子对象的所有MonoBehaviour中调用名称为methodName的方法
void ApplyDamage(float damage) { print(damage); } void Example() { gameObject.BroadcastMessage("ApplyDamage", 5.0F); }
GameObject.camera 摄像机
附加于这个游戏物体上的相机
public GameObject other; void Example() { other.camera.fieldOfView = 45; }
GameObject.collider 碰撞器
附加于这个游戏物体上的碰撞体
public GameObject other; void Example() { other.collider.material.dynamicFriction = 1; }
GameObject.collider2D 二维碰撞器
附加于此对象的2D碰撞器组件
Collider2D collider2D;
GameObject.CompareTag 比较标签
此游戏对象是否被标记为tag标签
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) Destroy(other.g