Professional Documents
Culture Documents
Microsoft
DOWNLOAD
Add the extension
Unity
In last tutorial, we discussed about unity interface. In this article, we will see
how to use GameObject and prefabs in a unity application.
GameObject Components
Alone GameObjects are nothing but the empty container, but when you will
add components to the GameObjects, it will add functionalities to them. By
default, there may be some components attached to your GameObjects. You
can see all the components of a GameObject in the Inspector window.
When you will create a new project in unity then by default there will be two
GameObjects in the hierarchy window.
Main Camera: Controls view of Game Window. What the camera will
see, the end user will see the same.
Directional Light: Provides light in any particular direction
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 1/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
Select any one of the GameObject in the hierarchy window then you can see
the attached components in the Inspector window. Select Main Camera and
check its components:
Disable Component
To disable any component, uncheck the checkbox located at top left of the
component, as shown in above image (1. Uncheck to disable component). If
any component is disabled, it will be attached to the GameObject but its
functionality will not render in the scene.
Remove Component
To remove any component, click on the icon located at top right of the
component, as shown in above image (2. Click to remove component). On Click,
following list will be displayed. Click on the Remove Component.
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 2/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
Add Component
You can also drag and drop items from assets folder to inspector window to
add component for any GameObject.
Transform Component
You can also transform the GameObject using transform tools with mouse
buttons.
Change GameObject
Properties using Inspector
Inspector window also allows you to disable and rename the GameObject
along with other features.
Rename GameObject
Rename the text box located at top of the Inspector and hit Enter to change the
name of the GameObject.
Static GameObject
Static GameObject will not move at play time. These are non-moving
GameObjects.
A tag is simply a string that can be used to reference one or more GameObjects
in the scene. You can group a type of GameObject with one tag like all the
enemy GameObjects in your game can be tagged as ENEMY tag. Change the
tag of a GameObject using Tag dropdown in inspector window.
Layer controls the rendering priority of GameObject in the scene. Change the
layer of a GameObject using Layer dropdown in inspector window. You can
refer my Layer Mask tutorial to know more about Layers.
Create a GameObject
Primitive GameObjects
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 4/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
You can create parent child relationship using GameObjects. Drag and drop
one GameObject to another to make it as the child of the another GameObject.
Prefabs
The prefab allows you to store a GameObject with all its components and
properties. Once a prefab is created the GameObject can be reused multiple
times across the scene and the projects.
Create a Prefab
Create Prefab by selecting Assets -> Create -> Prefab or Right Click to Assets
folder in Project window -> Create -> Prefab. Drag and drop a GameObject
from hierarchy to this newly created prefab.
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 5/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
You can also create prefab by directly by dragging and dropping GameObject
from hierarchy window to the project window.
Drag and drop prefab from project window (Asset Folder) to hierarchy to
instantiate prefab as the GameObject in the scene. You can instantiate same
prefab multiple times in a scene.
Edit Prefab
Select the prefab and you will see all of its properties and components in the
Inspector. Modify them upon your requirement, but all the modification will
DOWNLOA
the extension
also reflect on already instantiated GameObjects.
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 6/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
If you edit the GameObject (added by prefab) in the scene, it will not edit the
prefab by default. But, if we want to reflect the same change in the prefab then
click on apply button in the prefab section of inspector window after selecting
the GameObject.
Empty GameObject
You can also create empty GameObject in the hierarchy just like Cube and
other GameObjects. It will only have Transform component. It is mostly used to
create the parent of the multiple GameObjects.
Hope you get an idea about GameObjects and prefabs in unity application.
Post your comments for queries and feedback. Thanks for reading.
Gyanendu Shekhar
Gyanendu Shekhar is a technology enthusiast. He loves
to learn new technologies. His area of interest includes
Microsoft technologies, Augmented reality, Virtual reality,
unity3d and android development.
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 7/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
Gyanendu Shekhar
Gyanendu Shekhar is a technology enthusiast. He loves to learn
new technologies. His area of interest includes Microsoft
technologies, Augmented reality, Virtual reality, unity3d and
android development.
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 8/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Post Comment
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 9/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog
DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 10/10