Home and Learn: Games Programming Course

Textures and Walls in Unity

In the last lesson, you downloaded a first person controller and walked about on a bare floor. You're probably dying to get the gun in the player's hand and start blasting away. But let's hold off on that. First, we'll build a simple corridor so that the player has something to walk around in. Later, we'll add a soldier so that the player can shoot at something. We'll build something simple like this:

Top down view of walls and a floor

We'll get the first wall in place and then you'll learn how to add a texture.

For the first wall, add a new cube to your scene (Game Object > 3D Object > Cube). Rename it to Wall-1. With Wall-1 selected, change the Scale values in the Inspector on the right to these:


X: 0.2
Y: 6
Z: 40

The Rotation values can all be left on 0. For the Position on Wall-1, change them to these values:


X: -20
Y: 3
Z: 0

Here's what your Inspector should look like for Wall-1:

The Unity Inspector showing the Transform values for a wall

And here what it should look like in Scene view:

A cube used as a wall

Now let's add a texture to this wall.


Textures in Unity

A texture is a flat, 2D image wrapped around a 3D object. When you add things like normal maps, bump maps and specular maps, the 3D object then comes to life.

A good place to get textures for your projects is this site (it's not a https site, though, so your browser might start shouting at you.):

Texturise Club/

The textures are all royalty free and can be used anywhere. Let's use the texture here for our project:

Seamless White Brick Wall Texture Maps

There are three images on the page above. Grab them all. (Right-click > Save Image As.) But one is the texture and the other two are a Normal map and a Specular map. Save them to your computer. Open up an Explorer window (Windows key on your keyboard then the letter E). Navigate to the folder where you downloaded the images. Go back to Unity and create a folder under Assets in the Project area. Call it Textures. Now drag and drop the images into your new Textures folder:

Dragging textures into the Project area of Unity

When you let go of your left mouse button, you'll have three images in your Textures folder:

A texture, a normal map, and a specular map showing in Unity

Textures go on materials. When we added colours to our cubes in the previous game, we first created a material. The material was then dragged and dropped onto the cubes. However, you can drag and drop a texture onto a game object. But note what happens when you do.

Drag your texture (the first one) onto your wall:

Dragging a texture onto a wall

Notice that the texture is applied to the wall in your scene (it looks awful, at the moment):

Scene view showing the wall with a brick texture on it

Now click on your materials folder. Notice that Unity has created a material for you, with the same name as your texture image:

A material in Unity created from a texture

It's this material that you play around with when adjusting your texture.

With your Seamless material selected in the Project area, look at the Inspector on the right. Notice it has a shader item at the top:

The Standard Shader highlighted in the Inspector

We want to apply a specular map, so change the shader to Standard (Specular setup):

Switching to the Standard Specular shader

Go back to your Textures folder and drag and drop the third image onto the Specular item (make sure that your material is still selected, and not the texture):

Dragging a specular map onto the Inspector

You'll find that your wall is a bit too smooth, so turn the Smoothness slider down to half:

Adjust the smoothness of a specular map

Now, with the material still selected, drag the third texture image onto the Normal Map item:

Dragging a normal map onto the Inspector in Unity

Notice the two areas highlighted in red, in the image below:

creating a Normal map in Unity

The first one says that the texture is not marked as a normal map. Click the Fix Now button to solve that. This will give your wall a lot more definition. With that fixed, play around with the Tiling values under Emission to see what they do. We've gone for a value of 6 for the X value.

So your wall doesn't look so white, you can add a bit of colour, just like you did with the car in the previous game. Click the color square to the right of Albedo. Select a colour. We went for a hexadecimal value of 8C6A58, and our wall looks like this when we play the game and get up close to it:

The wall in Scene view with a normal and specular map applied

Looks a lot better than when we first dragged the texture onto the wall! Now that we have a decent looking wall, let's duplicate it a few times to create our corridors. Let's do the edges first.


Building Walls

In the Hierarchy on the left, select your Wall-1 item. Right-click and select Duplicate (or press CTRL+ D). Rename this new wall to Wall-2. You only need to change the X position of Wall-2 in the Inspector on the right. You can leave the other values alone. The X position of Wall-1 was -20. Change this to 20. (Just delete the minus sign.) Your Hierarchy and Scene view should look like this:

Duplicating a wall game object in Unity

Now we can just duplicate Wall-2, rotate it, and reposition. So, duplicate Wall-2. Rename it to Wall-3. With Wall-3 selected in the Hierarchy, change the values to these in the Inspector:


X: 0
Y: 3
Z: 20


X: 0
Y: 90
Z: 0

The Inspector should look like this for Wall-3:

Changing the Transform values of a game obejct

Now duplicate Wall-3. Rename it to Wall-4. You only need to change the Z position in the Inspector for Wall-4. Change it from 20 to -20. You will then have four walls in place:

A scene in Unity with four walls and a floor

OK, let's do a couple of interior walls now.

Click on Wall-2 in the Hierarchy. Duplicate Wall-2 and rename it to Wall-5. We need to rescale and reposition this wall. With Wall-5 selected, change the values in the Inspector to these:


X: 12
Y: 3
Z: 2.5


X: 0.2
Y: 6
Z: 35

The Inspector should look like this:

The Inspector showing the Transform values for an interior wall

And the Hierarchy and Scene should look like this:

An Interior wall in a scene

Now click on Wall-4 to select it. Duplicate Wall-4. Rename it to Wall-6. Now change the values in the Inspector to these:


X: -0.4
Y: 3
Z: -15


X: 0.2
Y: 6
Z: 25

The Inspector for Wall-6 should look like this:

In the Hierarchy, you should have this:

However, this looks a bit messy. What we can do is to create a parent for the walls and then group them. So, right-click in the Hierarchy and select Create Empty from the menu that appears: (Or click Game Object > Create Empty from the top of Unity.)

A Unity menu showing the Create Empty item

Unity creates an empty object. Rename the empty object to Walls. Now, select all your walls and drag them onto the Walls empty object:

The Hierarchy showing a group of game objects selected

Your Hierarchy should look like this:

The Hierarchy showing how to group items

You can now click the arrow to the left of Walls to expand or contract the item, making your Hierarchy a lot neater:

A group of contracted items

Before testing it out, let's reposition the player. Click on your player in the Hierarchy. (Click on First person controller full.) Now change the values for the Position and Scale in the Inspector to these:


X: 17
Y: 0
Z: 17


X: 2
Y: 2
Z: 2

We're changing the position to the start of the corridors. Changing the scale makes the player a bit taller. Your Inspector should look like this:

The Unity Inspector showing the Transfoen values for a first person controller

Now that we have a basic environment to walk around, let's arm our player. We'll do that in the next lesson below.

<--Back to the Unity 3D Course Contents Page

Email us: enquiry at homeandlearn.co.uk