Book Image

Unity 4.x Cookbook

By : Matt Smith, Chico Queiroz
Book Image

Unity 4.x Cookbook

By: Matt Smith, Chico Queiroz

Overview of this book

<p>Covering the latest version (Unity 4) of this established game engine, the Unity 4.x Cookbook explores a wide range of 3D, animation, multimedia, and scripting game features.<br /><br />The power of Unity 4 is demonstrated through the 10 chapters covering many of this game engine’s features.<br /><br />"Unity 4.x Cookbook" helps you learn how to make the most of the powerful but easy-to-use Unity 4 game engine. <br /><br />Every Unity game developer is different. Some come from a multimedia background, some are new to game development, and some are transferring from other engines. Whatever your background, with the breadth and depth of topics covered you should find new features and techniques to enhance your next game.<br /><br />This book offers detailed, easy-to-follow, step-by-step recipes helping you master a wide range of Unity game features. <br /><br />Chapters are provided focusing on the basics; audio, cameras, images, materials and animations, GUIs, external resources and devices, directional and artificial intelligence character control, and performance optimization.<br /><br />"Unity 4.x Cookbook" provides a collection of ideas and resources that should offer new and useful techniques for every Unity game developer to enhance their next game.</p>
Table of Contents (18 chapters)
Unity 4.x Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Controlling cube movement through player controls


Many of the recipes in this chapter are built on this basic project, which constructs a scene with a textured terrain, a downward facing Main Camera, and a red cube (as shown in the following screenshot) that can be moved around by the user using the four directional arrow keys.

How to do it...

To create a player-controlled cube, perform the following steps:

  1. Start a new project by navigating to Terrain Textures | GoodDirt.psd from the Terrain Assets Unity package (uncheck all of the other contents of this package as we don't need them and they'll just bloat the size of the project).

  2. Create a terrain, positioned at (-15, 0, -10) and sized 30 by 20.

    Note

    Transform position for terrains relates to their corner not their center

    Since the Transform position of terrains relates to the corner of the object, we center such objects at (0, 0, 0) by setting the X-coordinate equal to (-1 x width/2) and the Z-coordinate to (-1 x length/2). In other words, we...