Developing Game in Unity? Check Template Projects, Tools, VFX & many more!
HomeBlogUnity

Unity 3D How to Attach a Script or a Component to a Game Object

390

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

Scripts being blocks of code, written in C#.

Components being Unity's built-in elements, such as BoxCollider, Camera, MeshRenderer, etc.

To use a Script or a Component, it needs to be attached to an active Game Object.
There are multiple ways to attach Scripts and Components to Game Objects, use whichever method is the most convenient for you.

How to attach a Script?

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

Sharp Coder Video Player

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

Sharp Coder Video Player

Method 3: Select Game Object, then in the Inspector view click "Add Component":

Sharp Coder Video Player

How to attach a Component?

Method 1: Select Game Object, then in Inspector view click "Add Component":

Sharp Coder Video Player

Method 2: Select Game Object, then click "Component" menu:

Sharp Coder Video Player