Unity 3D is an open-source game engine used by indie developers and game studios. It is best known for its user-friendly platform, realistic graphics, and multi-platform publishing. This tutorial is great for beginners or anyone looking for a simple way to create a city in Unity.
Let's start by going to the Unity website. Unity 3D offers different packages. As an indie developer, their free package is exactly what you need to get started. Click Get Unity and download the package that is compatible with your system. Unity is both Mac and PC compatible, which makes it very popular. It is very important to check the system requirements. As of March 2016, they require a minimum of Windows 7 and Mac OS X 10.8 and above.
Next, you will want to register. By registering, you can keep track of your downloads and purchases from the Unity asset store. Once downloaded, Unity will start up. Depending on your system, it can take two to eight minutes. A dialogue box will open, asking you for your credentials. After you log in, it's time to start a new project.
Start a New Project and call it "My City". For the time being, do not choose any packages.
Pay close attention to the folder you add your projects, as all files need to remain in the same location. Keep the default location for this project. Once your project is open, go to File > New Scene, and name your scene "MyFirstCity".
At first, it will be a little overwhelming, but don't worry—we will take it step by step in order for you to understand what does what. At this point, your window should look like the picture below:
Let's begin at the bottom.
- The Project tab is where your project files, images, textures, and prefabs will go. It is good practice to keep your files organized from the very start. Games require tons of project files so it's better to start off on the right foot.
- The Console tab is where you will see any code or file errors.
- The Hierarchy tab will be where your current on-screen objects will be. Every project begins with a Light and Main Camera.
- The Scene tab shows your current scene through your main camera's focus.
- The Game tab shows you what your game looks like when it's being played.
- The Animator tab is where you will add your animator controller commands for your character.
- The Inspector tab is where you will see your current object details, for example, color, texture, scripts, etc.
The toggle bar contains the controls to move around in your world. Moving an object in the scene also moves it in real time on the game menu. Make sure you always save your scene to ensure your object stays in the position you want it. Let's go in order.
- The Hand icon allows you to grab the screen and move in the world freely.
- The Crossed Arrow symbol is used to move objects. In a 3D world, you can move up, down, left, and right.
- The Rounded Arrows are used to rotate your objects.
- The Outward Arrows are used to resize your object.
- The Box gives you an eye view. When you right-click your mouse, it allows you to see in a first-person view perspective.
Across the top bar, we have File, Edit, Assets, Game Objects, Component, Mobile Input, Window, and Help. The best way to learn about the menu is trial and error. We will go through the menu step by step later in this tutorial.
When you first open Unity, you will see the above layout. Go to Window then Layouts, and you can view the different layouts available in the Unity editor. Click each one until you are comfortable with them.
You can also create your own layout by left-clicking the tab and moving it anywhere you want. In my case, I use two monitors so I have my Game Scene on one monitor and my edit Scene in another. Play around with it until you're happy!
Now that we've created our scene and are happy with our layout, its time to download the assets we need for our project. Keep in mind any asset you bring into your scene can be used for multiple projects.
Go to Window and click the Asset Store. The asset store will open; here you will see hundreds of objects, textures, characters, and unity tools. You can purchase any item you would like. Although for this tutorial I will show you how to create your own textures, we will also download free assets. When you open the asset store for the first time, it may ask you to log in.
Let's start by typing Yughues Free Concrete Materials in the search box. Your window will look like the below sample.
Now click Download. After a few moments, a box will open. Click Import. Depending on your system it can take anywhere from two to ten minutes. Once it's imported, you will see your new asset in your Project tab.
Now let's go back to the asset store and import the City Props Pack. Repeat the above instructions.
We will also be downloading a skybox. Go back to the asset store and import Wispy Skybox.
Now it's time for our Unity packages. Go to Assets > Import Package. We will need the Characters, Cameras and Environment packages.
Finding Free Assets
We need a road and building textures, so in keeping my promise of free assets let's go to the web. Go to Bing and type "road", and once some images pop up, make sure that under the License section, Free Domain is chosen.
Feel free to choose any road you like, but a road with no background or sides would be best. You can also feel free to open the image in your editor and remove what is not needed. I have attached the road I used for this tutorial.
To keep things organized, save your images in your Unity folder. You may need to find where your files are being stored; usually, the default location is Public documents in My Computer. Now we need approximately five building textures. Click this Bing shortcut to be directed to the textures I used for this project. Right-click and save in the same Unity folder.
Tip: Always remember when using your projects commercially, it is better to be safe than sorry. You can visit websites like Envato Market to purchase royalty-free images.
Now let's create a folder in our Project tab and name it "Artwork". Go to Asset > Import Asset and choose your image. Move your image into your Artwork folder.
Tip: If you move your image once you have saved your project, there is a chance your image will not appear or appear pink (without a texture). Once all of your assets are downloaded, we are ready to begin setting up our world. Let's click File > Save Scene.
Let's Get Grounded
Let's add our terrain. Go to Game Object > 3D Object > Terrain. This will add a 3D Terrain into the scene. Now is a good time to play with the toggle menu to get used to moving around the world.
Tip: If your mouse has a wheel, you can use it to move closer or farther away from an object by clicking the Hand icon.
Once you add a terrain, your scene should look like the image above. There are a couple of reports of shader glitches when first opening Unity 5. If your project looks like the image below, don't worry—we will fix it! We will discuss lighting in another tutorial, but for now, click Terrain, and then under the Inspector tab choose the Cogwheel, scroll down to Material, and choose Built-In Legacy Diffuse. This should fix the issue.
When you choose an object in the Hierarchy, the objects detail will show in the Inspector window (on the right). This is where you can make changes to the object, add textures, add colliders and add code.
Let's get the camera in the correct position. Choose the Main Camera in the Hierarchy tab. Now look at the Inspector tab and on the right, under Transform, you will see Position. Type 265, 20, 20. Your camera should now be in the position where we want it.
Follow the Grey Brick Road
Now let's add a texture to the terrain. Choose Terrain from the Hierarchy tab and click the paint brush in the Inspector window. Under Textures you will see Edit Textures. Left-click and choose Add a Texture, and a small window will pop up asking you to choose a texture. Once you click that box, the textures you imported from the Asset Store will show. Double-click and add one you like. I chose Dark Concrete.
Look Into the Sky
Unity comes with a default skybox which works great if you like it. I think it's a little boring, so I'm going to add the skybox we downloaded earlier. Let's click Main Camera and in the Inspector window click Add Component at the bottom. Type Skybox and click the circle on the right. A box will open where you can choose a skybox of your choice by double-clicking it. Now if you look in your Game Scene you will see the new skybox. Looking good so far!
If You Build It
Now that our environment is coming along, let's add some buildings. Go to Game Object > 3D Object > Cube. At first, you won't see the cube because it's at a far distance. Let's get it to where we can see it. Click on Cube from the Hierarchy. Let's position the cube by typing 300, 25, 100. Let's also scale it to 20, 50, 20. You can use the scale tool or just type the size into the boxes. Once you've added the first Cube, right-click it in the Hierarchy tab to rename it. Name it Building 1.
Awesome. Let's add some more buildings. Repeat the steps above. You will see the additional cube in your Hierarchy as Cube (1), so let's rename it Building 2 by right-clicking your mouse and typing it in. Now scale to 20, 70, 20 and position to 275, 25, 100.
As you add buildings, change the scale and position for each one. Make sure you keep the middle positions at 25 to keep them lined up. You can also use the toggle bar to scale and move the buildings. Continue the steps until you have five buildings, and name them consecutively, for example Building 2, Building 3, and so on. I have my buildings positioned by skipping 25 numbers like so: 250, 0, 100, 225, 0, 100 etc. Don't forget to save your scene!
Tip: You can also right-click a building in the Hierarchy tab, copy and paste it.
Now we get to turn our cubes until buildings. Click on your Artwork folder in the Project tab (this is where you added your building textures). Choose a texture and drag it to a box on your Scene tab. You will immediately see the texture change in your Scene and Game views. Feel free to adjust, move and rotate your buildings until you're satisfied.
Tip: At times the texture can be backward. An easy fix is to rotate your box by changing the Z rotation to 180.
The Road Ahead
It's time to add the road. Go to Game Object > 3D Object > Plane. Position it at 250, 0.2, 80. Add a Y rotation of 90 and scale it to 1, 1, 15. Now choose your road texture and add it to the plane. Rename the plane Road.
A Place for Everything
Final Unity projects can have thousands of objects, scripts, and prefabs. It is important to keep your items organized, and now is a good time to organize your Hierarchy.
Any city is made up of numerous buildings, so let's keep ours itemized by the block. Go to Game Object > Create Empty, and you will now see a new item in your Hierarchy named GameObject. Rename it Block1(L). Click building 1, hold down Shift and highlight all of your other buildings. You can now move them all under Block1(L) which becomes the buildings' parent.
We will now create the other side of the street. Right-click Block1(L) and copy and paste. Name it Block1(R). Position Block1(R) to 235, -90, 300.
You can now change the textures around or download new ones if you wish. When changing a texture, you must click the individual box, otherwise you will change all the textures for the block. Let's reposition the Camera to 340, 10, 80 and rotate to -80.
Tip: If you don't like the way an item is positioned, you can move it with your toggle menu. Click save.
Adding City Props
From here on out we will need to use the toggle bar. Practice using the right and left mouse buttons to move around your world. It takes a little practice.
Click the down arrow on the City Props Pack folder in the Project tab. Scroll down to the Prefabs folder and click the down arrow until you see the list of objects. Choose the Stop sign. When you choose it you will see it displayed in the Inspector window on the right.
Let's move to the front of the first building. Choose the Stop sign and drag it to the Scene window; depending on your scene, you may need to scale it down. Scale to 0.2, 0.2, 0.2. Great!
Let's get creative and add more props. Feel free to choose the ones you like and place them anywhere you like on the sidewalk. Remember you can copy and paste any object in your Hierarchy. In the spirit of keeping things organized, create an Empty parent under Game Object and call it City Props. Move items accordingly. Save your scene.
Tip: Remember, if your objects glow white, you will need to change the shader to Legacy Shaders/Bumped Diffuse.
Now it's time to add some trees to our city. Unity comes with standard trees that work great. You can always download different types of trees from the asset store if you are going for a different look.
Let's click Terrain in the Hierarchy tab. In the Inspector window, you will see a picture of what looks like a tree under Terrain—click it. Under the settings, change the Brush Size to 1. Now click Edit Trees > Add Tree. In the Tree Prefab box, click the circle at the end.
Choose a tree (I chose Broadleaf). Double-click and add. You will now see the tree you chose under the Trees box in the Inspector tab. When you move your mouse on the Scene, a blue circle will follow. Since we have the Brush size on 1, you will place one tree at a time. If you add a tree and it's too large, you can resize under settings by changing the Tree Height. If you make a mistake, click Edit Trees and remove the tree. You can then start over.
Adding a Third-Person Character
OK, so we finally have our environment where we want it, and now it's time for our friend Ethan to walk around in our world. Click the down arrow under Standard Assets from the Project tab, then Characters > ThirdPersonCharacter. Go into Prefabs and drag the ThirdPersonController into your Scene. Position the controller at 315, 0.1, 78 and resize to 3, 3, 3.
You can also rotate him so he is facing the direction you want. Click Play, and you should be able to control Ethan. Click the arrow buttons on your keyboards and run around.
At some point, you will notice he moves off the screen, so we need the camera to follow him. Under Hierarchy, highlight the Main Camera and drag under ThirdPersonController. Your MainCamera should now be a child of the ThirdPersonController. Now when you hit play, the camera will follow Ethan.
Adding a First-Person Controller
We can also view our world in the first-person view. Go into your Project tab. Choose Standard Assets, Prefab, FPS Controller. Drag it to your scene, rotate and scale. Before you hit play, it is important to note that the FPS comes with its own camera, so you will need to delete the MainCamera.
Tip: If your character falls through the ground, you probably have them positioned too low. Double-click your character on the Hierarchy tab and you will see a close-up on the Scene tab. Move the controller up with the arrow bar or position the Y at 1.
Congratulations! You have built your first 3D City in Unity 5! As you can see, it's easy and lots of fun. You can get as creative as you like and add houses, cars, stores, etc. Stay tuned for more Unity tutorials coming soon!