Unity 常用脚本:GameObject

GameObject类

统一场景中所有实体的基类。游戏物体类。

脚本API

 脚本中直接写gameObject表示当前绑定此脚本的物体的gameObject。

属性:

public int layer { get; set; }游戏对象所在的层。层在[0…31]范围内。
public bool activeSelf { get; }游戏对象的局部活动状态(是否隐藏)。(只读)
public bool activeInHierarchy { get; }

游戏对象在场景中是否处于活动状态?

public bool isStatic { get; set; }指定游戏对象是否是静态的。
public string tag { get; set; }游戏对象的标签。
public Scene scene { get; }

游戏对象所在的场景。

public Component rigidbody { get; }附加到GameObject(游戏物体)上的刚体(只读)。(如果没有附加,则为空)。
public Component rigidbody2D { get; }附加到GameObject(游戏物体)上的刚体2D(只读)。
public Component camera { get; }连接到GameObject(游戏物体)上的摄像头(只读)。(如果没有附加,则为空)。
public Component animation { get; }附加到GameObject(游戏对象)的动画(只读)。(如果没有,则为空)。
public Transform transform { get; }附加到GameObject(游戏物体)上的transform 。
public Component constantForce { get; }附加到GameObject(游戏物体)上的恒力(只读)。(如果没有附加,则为空)。
public Component renderer { get; }附加到GameObject(游戏对象)的渲染器(只读)。(如果没有附加,则为空)。
public Component audio { get; }附加到GameObject(游戏对象)的AudioSource(只读)。(如果没有附加,则为空)。
public Component guiText { get; }附加到GameObject(游戏对象)的GUIText(只读)。(如果没有附加,则为空)。
public Component networkView { get; }附加到GameObject(游戏对象)的NetworkView(只读)。(如果没有附加,则为空)。
public Component guiTexture { get; }附加到GameObject(游戏对象)的GUITexture(只读)。(如果没有附加,则为空)。
public Component collider { get; }附加到GameObject(游戏对象)的collider (只读)。(如果没有附加,则为空)。
public Component collider2D { get; }附加到GameObject(游戏对象)的collider 2D(只读)。
public Component hingeJoint { get; }连接到GameObject(游戏物体)的铰链连接(只读)。(如果没有附加,则为空)。
public Component light { get; }连接到GameObject(游戏物体)上的灯光(只读)。(如果没有附加,则为空)。
public Component particleEmitter { get; }附加到游戏对象上的粒子发射器(只读)。(如果没有附加,则为空)。
public Component particleSystem { get; }附加到GameObject(游戏物体)上的粒子系统(只读)。(如果没有附加,则为空)。

方法

 public static GameObject Find(string name);

摘要:Finds a GameObject by name and returns it. 按名称查找GameObject并返回它。

public static GameObject[] FindGameObjectsWithTag(string tag);

 摘要:Returns a list of active GameObjects tagged tag. Returns empty array if no GameObject was found.

返回一个带有标签的活动游戏对象列表。如果没有找到GameObject,返回空数组。

按标签查找所有标记为此标签的物体并返回数组。

public static GameObject FindWithTag(string tag);

摘要:Returns one active GameObject tagged tag. Returns null if no GameObject was found. 

返回一个指定标签的显示的GameObject。如果没有找到GameObject,返回null。

public Component AddComponent(Type componentType); 

摘要: Adds a component class of type componentType to the game object. C# Users can use a generic version.

向游戏对象添加componentType类型的组件类。c#用户可以使用通用版本。

public Component AddComponent(string className);

摘要: Adds a component class named className to the game object.向游戏对象添加一个名为className的组件类。 

public bool CompareTag(string tag); 

摘要: Is this game object tagged with tag ?这个游戏对象有标签吗?

public Component GetComponent(string type);

摘要: Returns the component with name type if the game object has one attached, null if it doesn't.

如果游戏对象有名称类型的组件,则返回该组件;如果没有,则返回null。

public Component GetComponent(Type type);

摘要:Returns the component of Type type if the game object has one attached, null if it doesn't. 

如果游戏对象有一个附加组件,则返回Type类型的组件,如果没有,则返回null。

public void SetActive(bool value); 

摘要:Activates/Deactivates the GameObject.激活/失活GameObject。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值