Book Image

Mastering UI Development with Unity

By : Ashley Godbold
Book Image

Mastering UI Development with Unity

By: Ashley Godbold

Overview of this book

A functional UI is an important component for player interaction in every type of video game. Along with imparting crucial statistical information to the player, the UI is also the window through which the player engages with the world established by the game. Unity's tools give you the opportunity to create complex and attractive UIs to make your game stand out. This book helps you realize the full potential of Unity's powerful tools to create the best UI for your games by walking you through the creation of myriad user interface components. Learn how to create visually engaging heads-up-displays, pause menus, health bars, circular progress bars, animated menus, and more. This book not only teaches how to lay out visual elements, but also how to program these features and implement them across multiple games of varying genres. While working through the examples provided, you will learn how to develop a UI that scales to multiple screen resolutions, so your game can be released on multiple platforms with minimal changes.
Table of Contents (12 chapters)

Accelerometer and gyroscope

Most mobile devices have a built-in accelerometer, and many also have a gyroscope. Without getting too technical in describing how it actually works, the difference between the accelerometer and the gyroscope is what they measure. The accelerometer measures acceleration within the 3D coordinate system, and the gyroscope measures rotation.

You can access data from the device's accelerometer using the Vector3 Input.acceleration property.

The coordinates of Input.acceleration line up with the scene based on the rotation of the device, as shown:

Simple examples of this involve moving an object around a scene when the device is moved, using something like the following within an Update() function on the object:

transform.Translate(Input.acceleration.x, 0, -Input.acceleration.y);

The gyroscope uses more complicated mathematics to get more precise movement...