Unity How to Attach a Script or a Component to a GameObject

In video games and specifically in Unity, almost all aspects are controlled by Scripts and Components.

  • Scripts are blocks of code, written in C#
  • Components are Unity’s built-in elements, such as BoxCollider, Camera, MeshRenderer, etc.

To use Scripts and Components, they need to be attached to an active GameObject.

Attach a Script

To attach a script to a GameObject use the methods below:

Method 1: Drag & drop the script from the Project view directly to the GameObject:

Method 2: Select GameObject, then drag & drop the script to the Inspector view:

Method 3: Select GameObject, then in the Inspector view click “Add Component”:

Attach a Component

To attach a Component to a GameObject use the methods below:

Method 1: Select GameObject, then in Inspector view click “Add Component”:

Method 2: Select GameObject, then click the “Component” menu:

Leave a Reply

Your email address will not be published. Required fields are marked *