Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Unity 2018 By Example - Second Edition

You're reading from  Unity 2018 By Example - Second Edition

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781788398701
Pages 484 pages
Edition 2nd Edition
Languages

Table of Contents (16) Chapters

Unity 2018 By Example - Second Edition
Contributors
Preface
Other Books You May Enjoy
1. Unity Fundamentals 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 Test Your Knowledge Answers Index

Adding a coin to collect


On reaching this far, our game has many features, namely, a complete environment, first-person controller, and water. However, we're supposed to be making a coin collection game and there aren't any coins for the player to collect yet. Now, to achieve fully collectible coins, we'll need to write some C# script, which will happen in the next chapter of this book. However, we can at least get started here at creating the coin object itself. To do this, we'll use a Cylinder primitive that's scaled to form a coin-looking shape. To create a cylinder, select GameObject | 3D Object | Cylinder from the application menu:

Figure 1.57: Create a Cylinder

Initially, the cylinder looks nothing like a coin. However, this is easily changed by scaling non-uniformly in the Z axis to make the cylinder thinner. Switch to the scale tool (R) and then scale the Cylinder inward. See Figure 1.58:

Figure 1.58: Scaling the cylinder to make a collectible coin

After rescaling the coin, its collider no longer represents its volume. It appears much larger than it should (see Figure 1.58). By default, the Cylinder is created with a Capsule Collider as opposed to a Box Collider. You can change the size of the Capsule Collider component by adjusting the Radius field from the Object Inspector when the coin is selected. Lower the Radius field to shrink the collider to a more representative size and volume. See Figure 1.59. Alternatively, you could remove Capsule Collider altogether and add Box Collider instead. Either way is fine; generally choose the simpler shape where possible. The colliders will be used in script in the next chapter to detect when the player collides with the coin to collect them:

Figure 1.59: Adjusting the Capsule Collider for the coin

Here we are! We now have the basic shape and structure for a coin. We will, of course, improve it carefully and critically in many ways in the next chapter. For example, we'll make it collectible and assign it a material to make it look shiny. However, here, using only a basic Unity primitive and scale tool, we're able to generate a shape that truly resembles a coin.

You have been reading a chapter from
Unity 2018 By Example - Second Edition
Published in: Jul 2018 Publisher: Packt 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 $15.99/month. Cancel anytime}