Javatpoint Logo
Javatpoint Logo

Unity GameObjects

The GameObject is the most important thing in the Unity Editor. Every object in your game is a GameObject. This means that everything thinks of to be in your game has to be a GameObject. However, a GameObject can't do anything on its own; you have to give it properties before it can become a character, an environment, or a special effect.

A GameObject is a container; we have to add pieces to the GameObject container to make it into a character, a tree, a light, a sound, or whatever else you would like it to be. Each piece is called a component.

Depending on what kind of object you wish to create, you add different combinations of components to a GameObject. You can compare a GameObject with an empty pan and components with different ingredients that make up your recipe of gameplay. Unity has many different in-built component types, and you can also make your own components using the Unity Scripting API.

Three important points to remember:

  1. GameObjects can contain other GameObjects. This behavior allows the organizing and parenting of GameObjects that are related to each other. More importantly, changes to parent GameObjects may affect their children ? more on this in just a moment.
  2. Models are converted into GameObjects. Unity creates GameObjects for the various pieces of your model that you can alter like any other GameObject.
  3. Everything contained in the Hierarchy is a GameObject. Even things such as lights and cameras are GameObjects. If it is in the Hierarchy, it is a GameObject that's subject to your command.

Creating and Destroying GameObjects

Some games handle a number of objects in the scene, but we can also create and remove the treasures, characters, and other objects during gameplay.

In Unity, we can create a GameObject using the Instantiate function, which makes a new copy of an existing object:

Unity can also provide a Destroy function that is used to destroy an object after the frame update has finished or optionally after a short time delay:

Note that the Destroy function is also used to destroy individual components without affecting the GameObject itself. A common mistake is to write something like:

Next TopicUnity Components

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA