【Unity】入门学习笔记180517——API(4)——GameObject类

GameObject类

一个GameObject对象通常由多个组件component组成,且至少含有一个Transform组件


A、实例属性

1、activeSelf:

public bool activeSelf{ get; }

返回Gameobject对象的Active标识状态

与activeInHierarchy属性的区别在于不受父类的激活状态影响

即即使父类状态未激活,子类状态激活,即使程序运行不显示,但仍然返回True


B、构造方法

public GameObject();

public GameObject(String name);

public GameObject(String name, params Type[] components);


C、实例方法

1、GetComponent / GetComponentInChildren /GetCompinents / GetComponentsInChildren

获取组件

public T GetComponent<T>() Where T: Component;

public Component GetComponent(string type);

public Component GetComponent(Type type);


2、SendMessage

public void SendMessage(string methodName);

~(string methodName, object value);

~(string methodName, SendMessageOptions options);

~(string methodName, object value, SendMessageOptions options);

参数options为信息接收的方式,默认为SendMessageOptions.RequireReceiver

向GameObject自身发送消息,有作用范围:

①和自身同级的物体不会收到消息

②DontRequireReceiver不要求信息的接收方必须有接受消息的方法


此外,还有

BroadcastMessage:向自身及其所有子类发送消息,自身同级物体不会收到消息

SendMessageUpwards:向自身及其所以父类发送消息,自身同级物体不会收到消息


D、静态方法

1、CreatePrimitive

public static GameObject CreatePrimitive( PrimitiveType type);

参数使用例如:PrimitiveType.Sphere

创建一个系统自带的GameObject对象



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值