建设银行招聘网站甘肃分行,主要的cms系统有哪些,唐山高端品牌网站建设,制作一个网页的步骤GameObject类
GameObject类是Unity场景中所有实体的基类。一个GameObject对象通常由多个组件组成#xff0c;且至少含有一个Transform组件。
1、GameObject类实例属性
在GameObject类中#xff0c;实例属性有activeSelf和activeInHierarchy。
activeSelf属性#xff1a;…GameObject类
GameObject类是Unity场景中所有实体的基类。一个GameObject对象通常由多个组件组成且至少含有一个Transform组件。
1、GameObject类实例属性
在GameObject类中实例属性有activeSelf和activeInHierarchy。
activeSelf属性GameObject的Active标识 基本语法 public bool activeSelf { get; } 功能说明此属性与属性activeInHierarchy的区别。activeInHierarchy属性的功能是返回GameObject实例在程序运行时的激活状态它只有当GameObject实例的状态被激活时才会返回ture。而且它会受其父类对象激活状态的影响如果其父类至最顶层的对象中有一个对象未被激活。
2、GameObject构造方法
基本语法
1、public GameObject()
2、public GameObject(string name)
其中参数name为构造GameObject对象的名字
3、public GameObject(string name , params Type[] components)
其中参数name为构造GameObject对象的名字components为构造对象要添加的组件类型集合多个组件之间用逗号隔开功能说明 此构造方法用来创建一个GameObject对象 //使用构造函数GameObject(name : String)GameObject g1 new GameObject(G1);g1.AddComponentRigidbody();//使用构造函数GameObject()GameObject g2 new GameObject();g2.name G2;g2.AddComponentFixedJoint();//使用构造函数GameObject(name : String , params components : Type[])GameObject g3 new GameObject(G3, typeof(MeshRenderer), typeof(Rigidbody), typeof(SpringJoint));Debug.Log(g1 name: g1.name \nPosition g1.transform.position);Debug.Log(g2 name: g2.name \nPosition g2.transform.position);Debug.Log(g3 name: g3.name \nPosition g3.transform.position);3、GameObject类实例方法
在GameObject类中涉及的实例方法有GetComponent、GetComponentInChildren、GetComponents、GetComponentsInChildren、SendMessage、BroadcastMessage 和 SendMessageUpwards。
3.1、GetComponent方法获取组件
基本语法
1、public T GetComponentT() where T:Component;
2、public Component GetComponent(string type);
其中参数type为组件名
3、public Component GetComponent(Type type);
其中参数type为组件类型功能说明此方法用于获取GameObject中第一个符合Type类型的Component。
3.2、SendMessage方法发送消息
基本语法
1、public void SendMessage(string methodName);
2、public void SendMessage(string methodName, object value);
3、public void SendMessage(string methodName, SendMessageOptions options)
4、public void SendMessage(string methodName, object value , SendMessageOptions options)四个重载方法涉及的参数有 1、methodName为接受信息的方法名字 2、value为信息的内容 3、options为信息接收的方法 4、默认为SendMessageOptions.RequireReceiver
功能说明此方法的功能是向GameObject自身发送信息对其作用范围说明 1、和自身同级的物体不会收到消息 2、SendMessageOptions有两个可选方式SendMessageOptions.RequireReceiver和SendMessageOptions.DontRequireReceiver。 前者要求信息的接受方必须有接受信息的方法否则程序会报错后者则无此要求
BroadcastMessage方法的功能是向自身及其所有子类发送信息。和自身同级的物体不会收到信息。 SendMessageUpwards方法的功能是向GameObject自身及其所有父类发送消息。和自身同级的物体不会收到信息。
private void Start(){//向子类及自己发送消息gameObject.BroadcastMessage(GetParentMessage, gameObject.name : use BroadcastMessage send);//向自己发送信息gameObject.SendMessage(GetSelfMessage, gameObject.name : use SendMessage send );//向父类及自己发送信息gameObject.SendMessageUpwards(GetChildrenMessage, gameObject.name ues SendMessageUpwards send );}//一个接受父类发送信息的方法private void GetParentMessage(string str){Debug.Log(gameObject.name 收到父类发送的信息 str);}//一个接受自身发送信息的方法private void GetSelfMessage(string str){Debug.Log(gameObject.name 收到自身发送的消息 str);}//一个接受子类发送信息的方法private void GetChildrenMessage(string str){Debug.Log(gameObject.name 收到子类发送的消息 str);}4、GameObject类静态方法
在GameObject类中涉及的静态方法主要有CreatePrimitive。在使用该方法创建GameObject对象时往往会涉及添加组件(AddComponent)和查找对象(Find)。
4.1、 CreatePrimitive方法创建GameObject对象
基本语法
public static GameObject CreatePrimitive(PrimitiveType type);
其中参数type为PrimitiveType的类型值功能说明 此方法的功能是创建一个系统自带的GameObject对象
关于GameObject类和Component类的使用注解 GameObject和Component是Unity中很常用而且十分重要的两个类二者的实例属性和实例方法相似只是在使用方法上稍有区别。 1、通过一个GameObject对象由多个Component组成而且一个GameObject对象至少有一个Transform组件。GameObject用来管理工程中的各个物体而Component用来扩展这些物体自身的功能。 2、GameObject类和Component类的属性名称和方法名称基本相同各个属性和方法的用法也很相近但它们任有一些差别。 若要获取当前脚本所在在GameObject对象中的某个组件直接使用GetComponent方法即可。若要获取非当前脚本所在GameObject对象中的某个组件则需要有GameObject作为前置引用。