Unity Tutorials 3 - Game Objects I - Gameobjects: Cleaning Up The Scene
Unity Tutorials 3 - Game Objects I - Gameobjects: Cleaning Up The Scene
I – GameObjects
Try deleting the asset too. Same as before, right click the image under Assets and press
delete, or highlight it and press the DEL key. Once deleted, you can check your Assets
folder to see that it is gone.
Adding 3D Objects
Besides adding completed 3D models, you can also add standard 3D objects, like cubes
and spheres, into a scene. You can even group these objects together to create a larger
object.
First, go into “GameObject” on the top bar, “3D Object”, and “Cube”.
Unity Tutorials 3 – Game Objects
With the move tool selected, notice that the arrows originate from the centre of the cube.
Note: The pivot point of an object cannot be directly changed in Unity. That being said,
there is a way to do it which we will get to later.
Now try making one of each 3D object. You should have a cube, a sphere, a capsule, a
cylinder, and a plane. Don't worry about the quad. A quad is like a small plane.
Parenting Objects
Now we're going to create one large object out of these smaller objects. This process is
known as “parenting”. An object that is parented to another object becomes dependant
on it. Any transformation that is done to the parent object will be done to any child
Unity Tutorials 3 – Game Objects
object as well.
First you will need to make an empty game object. An empty object is just what it
sounds like. It's an invisible object with no attributes. You can find it in the GameObject
menu. Click “Create Empty”. You can also right click inside the hierarchy to bring up
the GameObject menu. Make sure that you don't have another object selected or the
empty object will become parented to it. You can unparent an object by dragging it out
of the parent to an empty space in the hierarchy.
Now before we begin, let's set up our parent object. First, rename it. Next, check its
tranform in the inspector. Set the position to (0, 0, 0). This is where we want the centre
of our completed object to be.
Unity Tutorials 3 – Game Objects
Now set up your objects however you want them, but first move your plane to (0, 0, 0).
Since it will be the central part of our complete object, it would make sense to have its
pivot and the parent's pivot at the same location.
Parenting objects is very easy. Just go to the hierarchy and click and drag each object
into the parent object.
Make sure that you are parenting each object to the actual parent and not to one of the
childs in the parent.
You can click the little arrow next to the parent to hide the childs. This is convenient for
organizing your hierarchy. For example, say you have multiple of the same enemy in a
scene. You can parent all of these enemies to one empty object. The hierarchy can be
very difficult to manage once it is full of objects, so keeping it organized is a good idea.
Unity Tutorials 3 – Game Objects
Let's try using the scale tool on the parent object. Select the parent object then select the
scale tool. You can use it just like the move and rotate tools.
You can see that all the parented objects scale with the parent. Now, try resetting the
scale. Scale is based on multiplications. Whatever the number is in the transform, the
size of the object will be its original size times that number. So, the default scale is 1.
This is because right now we have the tools set to act on the centre of an object and not
its pivot. Next to the tools are two buttons. Click the one on the left.
With the parent object selected you should be able to see how the arrow's location
changes to where we originally set it. To see the difference, change the button back to
“Center” and try rotating the parent object.
You can see that the position of the object Vector: The smallest part of a
does change slightly. This is because the polygon. A vector is basically like a
centre of the object doesn't move. Instead, the point on a graph. Each quad (four
object moves around it. You might also notice sided polygon) has 4 vectors.
that you can only see the plane from one side.
This is the same for every face in Unity, but
we'll cover that later. Side: The middle part of a polygon.
Each side is made up of a line
Now change the rotation and position back to between two vectors, or points.
(0, 0, 0) and change the “Center” button to
“Pivot”. Try rotating the object now. Face: A face is an area surrounded
by 3 or more sides.
Notice how not only does the position not
change, but the objects now rotate under the
grid. Polygon: A 2D shape. Every 3D
model is made up of many
polygons put together.
Unity Tutorials 3 – Game Objects
Unity Tutorials 3 – Game Objects
II – Applying Materials
Try creating five different materials and apply them to your objects. First, right-click
inside the Assets window. Under “Create” you'll see a long list of assets that you can
create from scratch. Click on “Material”.
Once you've made your first material you can highlight it and hit CTRL and D. This will
duplicate it. Next, rename your materials.
Unity Tutorials 3 – Game Objects
Let's take a look at the inspector for one of the Texture Map: In 3D modelling, a
materials. You can see that there are a number of texture map is a flat image
different “maps” as they're called. The albedo is designed in such a way that it can
the main texture that decides the base colouration be wrapped around the model.
of the material. This is where you would put a Imagine cutting a head mask up
texture map. the back then flattening it.
Next let's try using a texture instead of a colour. First, find an image on the internet and
save it to your Assets folder. Or you can save it somewhere else and import it after.
Select the material you want to apply it to and click on the little circle next to “Albedo”.
Alternatively, you can drag-and-drop the texture right onto the circle.
If you clicked the circle, a box will show up listing viable assets. Double-click on the
texture that you saved. Remember, since this texture hasn't been mapped to fit the model
it will look strange unless it is a pattern. For example, you can safely use a wood pattern
as a material for floors or a rock pattern as a material for a boulder. But when it comes to
characters, unless you have their bodies split up into numerous objects, a texture map
will be required.
Unity Tutorials 3 – Game Objects
III – Prefabs
What is a prefab?
Prefabs are pre-made objects that are stored as an asset. It is wise to always use prefabs
when you can.
Making a prefab is very easy. Just like how you created a new material, right-click in the
Assets window and under “Create” click “Prefab”.
Rename your prefab. Now drag-and-drop your parent object into it.
Notice that the parent object and all of the objects within it are blue in the hierarchy.
This means that they were created using a prefab.
Delete the original parent object. Now drag-and-drop your prefab into the hierarchy or
the scene view. This is how you will most often be placing models into your scene. Let's
try making an even bigger prefab using this one.
Now drag 3 more prefabs into your scene to make a total of four. After that, move them
around so that you make a large square. Now in the hierarchy make an empty object.
Before you parent the four prefabs to it you should move it into a proper position. The
centre of your large square will be something similar to (5, 0, 5) depending on how you
formed it. When that is ready, parent the four clusters to the empty object. Once that is
complete you can drag it into the new prefab.
Now let's try rearranging the objects so that the four squares aren't identical. Click the
drop-down arrow for one of the four clusters to individually select one of the objects in
it.
Unity Tutorials 3 – Game Objects
Now you can change that object's location separately from all the others. Do this to a
few of the objects. Once you are finished, select the top parent (bigCluster) and change
the scale to (2, 2, 2). Now drag this object into its prefab in the Asset window again.
This will update the prefab.