Javatpoint Logo
Javatpoint Logo

Unity Components

Unity is a component-based system. Unity components are functional pieces of every GameObject. If you don't understand the relationship between components and GameObjects, first read the GameObjects page before going any further.

To give functionality to a GameObject, you attach different components to it. Even your scripts are components. So we can say, components are isolated functionality that can be attached to an object to give that functionality to that particular object. That means, when an object requires a specific type of functionality, you add the relevant component.

A GameObject is like a container for many different components. By default, all GameObject automatically have a Transform component. This is because the Transform defines where the GameObject is located and how it is rotated and scaled. Without a Transform component, the GameObject would not have a location in the world.

Creating a GameObject

Let's create an empty GameObject:

  • From the menu bar click on GameObject -> Create Empty
Unity Components
  • Select the new GameObject, and look at the inspector from the top left corner of the window.
Unity Components

Here we can see that even empty GameObject have a Transform Component.

Unity Components

Adding Components

We can add the components to the selected GameObject by the Components menu. Let's try to add a Rigidbody to the empty GameObject we just created. To do that, follow the following steps:

  • Select the GameObject and from the menu bar choose Component -> Physics -> Rigidbody.
Unity Components
  • When you do this, you will get the Rigidbody's properties appear in the inspector.
Unity Components
  • Another option is to use the Component Browser to open this Component Browser press 'Add Component' button.
Unity Components

This browser lets you navigate the components by category and also has a search box that you can use to locate components by name.

We can attach any number or combination of components to a single GameObject. One another important feature of Components is flexibility. When we add a component to a GameObject, there are different values of Properties in the component that can be adjusted in the editor while building a game, or by scripts when running the game.

Next TopicUnity Interface

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA