Joke Collection Website - Blessing messages - How to convert Object to UnityEngine.GameObject
How to convert Object to UnityEngine.GameObject
You can manually create a GameObject through the Create menu under the Hierarchy panel. It can be a camera, a light, or a simple model. When we want to dynamically create a camera in the program, You can create a new GameObject and then add the Camera component to it. Creating lights, GUI, etc. is also similar. But when I want to create a simple model, I found that there are no components like Cube and Sphere to add. I will know later. This purpose can be achieved through a static method of the GameObject class static GameObject CreatePrimitive(PrimitiveType type); five types of basic models can be created based on PrimitiveType PrimitiveType.Plane, PrimitiveType.Cube, PrimitiveType.Sphere, PrimitiveType.Capsule, PrimitiveType.Cylinder Unity3D Provides a prefab object called Prefab, which is a GameObject saved on the hard disk in the form of a file. It may contain various settings, components, and some scripts. Prefab allows us to use the same object in different Scenes or even Projects. For example, I implemented a bullet, and by packaging it into Prefab, I can use it directly in another game.
When a Prefab object is modified, all its instances will be modified accordingly. To dynamically instantiate a Prefab object in the code, public GameObject obj; obj = Instantiate( obj); must first create a public variable, and then set the Prefab Drag it to this variable, and then use it to instantiate the object (I feel a kind of sadness, can you not drag it)? Through the static method of the Resources class, the Prefab object can be dynamically loaded in, and the GameObject and GameObject can be created. Communication, in games, we often need to know some information about other objects, so we often need to dynamically query another GameObject 1. Find the parent node transform.parent 2. Find the child node transform.Find("name"); transform. Find("Arm/Hand/Finger"); If not found, null will be returned. If the name contains the "/" character, it will traverse the hierarchy like a path. 3. Find other GameObjects in the scene. GameObject.Find starts from the Scene and searches according to the GameObject. To search by name, you can use "/" to search across levels. GameObject.FindWithTag searches for a GameObject based on Tag. GameObject.FindGameObjectsWithTag searches for GameObjects in batches based on Tag. The name and Tag of GameObject can be set directly, but Tag needs to be defined in the tag manager first. , only this Tag can be used. You cannot assign an undefined Tag to the Tag variable of GameObject. Finally, there is a communication method to call other GameObjects through Message. The default is to send spam messages in bulk. You can also pass an Object through it. , and then adjust its method methodName as the method name, value as the parameter of the method, options indicate whether there must be an object to receive the message (if so, and no object accepts, u3d will report an error) //Call all scripts on all GameObjects at this level methodName method void SendMessage(string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver); //Send the calling command to this level and the superior parent node void SendMessageUpwards(...) //The target is this level and all child nodes ... void BroadcastMessage(...) Calling the Destroy method of Object can destroy a GameObject, component, or resource. This is a static method. The prototype of the function is static void Destroy(Object obj, float t = 0.0F); You can destroy yourself by passing this in. GameObject has many member variables
- Related articles
- What is the merchant number of Tonglian cashier Bao?
- Why didn't Ping An Bank receive short messages recently?
- I'm nervous when I'm with a boy. Give him information. Do I like him?
- How does Nokia 523 export SMS from memory card with OVI suite?
- What message does the moving diamond send?
- Teacher's Day blessing: Thank you for your selfless dedication.
- Warm words for girls
- In Guangzhou, the monthly income is 8000. What level is this? Can you live in Guangzhou?
- Huawei's cloud hosting reminder space is insufficient and it doesn't want to upgrade the space. How do I turn off reminders?
- Can I get a passport online?