Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 2018 By Example

You're reading from   Unity 2018 By Example Learn about game and virtual reality development by creating five engaging projects

Arrow left icon
Product type Paperback
Published in Jul 2018
Publisher
ISBN-13 9781788398701
Length 484 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Alan Thorn Alan Thorn
Author Profile Icon Alan Thorn
Alan Thorn
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Unity Fundamentals FREE CHAPTER 2. Creating a Collection Game 3. Creating a Space Shooter 4. Continuing the Space Shooter 5. Creating a 2D Adventure Game 6. Continuing the 2D Adventure 7. Creating Artificial Intelligence 8. Continuing with Intelligent Enemies 9. Entering Virtual Reality 10. Completing the VR Game A. Test Your Knowledge Answers Other Books You May Enjoy Index

Scene building

Now that we've seen how to transform objects and navigate the scene viewport successfully, let's proceed to complete our first level for the coin collection game. Let's separate the two floor meshes apart in space, leaving a gap between them that we'll fix by creating a bridge, which the player will be able to cross, moving between the floor spaces like islands. We can use the translate tool (W) to move objects around. See Figure 1.29:

Scene building

Figure 1.29: Separating the floor meshes into islands

Tip

If you want to create more floor objects, you can use the method that we've seen already by dragging and dropping the mesh asset in the Project panel in the Scene viewport. Alternatively, you can duplicate the selected object in the viewport by pressing Ctrl + D on the keyboard. Both methods produce the same result.

Next, we'll add some props and obstacles to the scene. Drag and drop some house objects onto the floor. The house object (HousePrototype16x16x24) is found in the Assets | Standard Assets | Prototyping | Prefabs folder. See Figure 1.30:

Scene building

Figure 1.30: Adding house props to the scene

On dragging and dropping the house in the scene, it may align to the floor nicely with the bottom against the floor, or it may not align like that. If it does, that's splendid and great luck! However, we shouldn't rely on luck every time because we're professional game developers! Thankfully, we can make any two mesh objects align easily in Unity using vertex snapping. This feature works by forcing two objects into positional alignment within the scene by overlapping their vertices at a specific and common point.

For example, consider Figure 1.31. Here, a house object hovers awkwardly above the floor and we naturally want it to align level with the floor and perhaps over to the floor corner. To achieve this, start by selecting the house object (click on it or select it from the Hierarchy panel). The object to be selected is the one that should move to align and not the destination (which is the floor), which should remain in place:

Scene building

Figure 1.31: Misaligned objects can be snapped into place with Vertex Snapping

Next, activate the translate tool (W) and hold down the V key for vertex snapping. With V held down, move the cursor around and see how the Gizmo cursor sticks to the nearest vertex of the selected mesh. See Figure 1.32. Unity is asking you to pick a source vertex for the snapping:

Scene building

Figure 1.32: Hold down V to activate Vertex Snapping

With V held down, move the cursor to the bottom corner of the house, and then click and drag from the corner to the floor mesh corner. The house will then snap align to the floor, corner to corner. When aligned this way, it releases the V key, and the two meshes get aligned exactly at the vertices. See Figure 1.33:

Scene building

Figure 1.33: Align two meshes by vertices

Now you can assemble a complete scene using the mesh assets included in the Prototyping package. Drag and drop props in the scene, and using translate, rotate, and scale, you can reposition, realign, and rotate these objects; using vertex snapping, you can align them wherever you need. Give this some practice.

See Figure 1.34 for the scene arrangement that I made using only these tools and assets:

Scene building

Figure 1.34: Building a complete level

You have been reading a chapter from
Unity 2018 By Example - Second Edition
Published in: Jul 2018
Publisher:
ISBN-13: 9781788398701
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image