"Unity_api Analysis" chapter III Gameobject Class

Source: Internet
Author: User
Tags instance method

Gameobject Class Instance Properties

Activeself property: Active identity for Gameobject

public bool activeself{get;} Function Description This property is used to return the active identity state of the Gameobject object, which is the active state of the object. Note: This property differs from Activeinhierarchy. The function of the Activeinhierarchy property is to return the activation state of the Gameobject instance when the program is running, and returns true only if the state of the Gameobject instance is activated. And it is affected by the activation state of its parent object, and Activeinhierarchy returns False if an object in its parent class to the topmost object is not activated.  gameobject class Construction Method 1.public Gameobject (); 2.public gameobject (string name); parameter is the name of the constructed Gameobject object 3.public Gameobject (String name,params type[]  components); The parameter is the name of the Gameobject object, components are the set of component types to be added by the construction object, separated by commas between multiple components. Function Description This construction method is used to create a Gameobject object.  gameobject class Instance method Getcomponent method: Get component 1.public T getcomponent<t> where T:component;2.public Component Getcomponent (String type) where the parameter type is the component name. 3.public Component getcomponent (type type), where the parameter type is a component type. Function Description This method is used to get the first component in Gameobject that conforms to type. Note: Methods that are similar to this method have Getcomponentinchildren,getcomponents and Getcomponentsinchildren. 1. When using the Getcomponents (Type:type) method component[] CJs = getcomponents (typeof (Configurablejoint)) as component[]; It is not possible to write this: configurablejoint[] CJs = getcomponents (typeof (ConfigurAblejoint) as configurable joint[]; Because Configurablejoint is not component, but its subclasses, it is recommended to use its generic mode. 2. You cannot write this when using the Getcomponentsinchidren (Type:type,includeinactive:boolean = False) method. component[] CJs = Getcomponentsinchildren (typeof (Configurablejoint), false) as component[]; configurablejoint[] CJs = Getcomponentsinchidren (typeof (Configurablejoint), false) as configurablejoint[]; Because Configurablejoint is not a component, it is a subclass and it is recommended to use its generic style.  sendmessage method: Send Message 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), parameter MethodName is the method name to receive the message, value is the content of the information, options is the way to receive the information, The default is Sendmessageoptions.requirereceiver. Function Description The function of this method is to send a message to gameobject itself, and its scope of action is as follows: 1. Objects that receive the same sibling as the message object do not receive messages. The 2.SendMessageOptions is available in two options: Sendmessageoptions.requirereceiver and Sendmessageoptions.dontrequirereceiver. The former requires the recipient of the information must have the method of receiving information, or the program will error, the latter is not required. Hint: A method similar to this method has BROadcastmessage and Sendmessageupwards, their functions are described as follows: The function of the 1.BroadcastMessage method is to send a message to the object itself and all its subclasses. Objects at the same sibling as the object do not receive messages. The function of the 2.SendMessageUpwards method is to send messages to the object itself and all its parent classes. Objects of the same level as themselves do not receive messages.  gameobject class static method Createprimitive method: Create Gameobject object public static Gameobject createprimitive (PrimitiveType type) ; The parameter is the type value of the enumeration PrimitiveType. Function Description: The function of this method is to create a system-Gameobject object.

Unity_api Analysis Chapter III Gameobject class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.