Book Image

Unity 5 for Android Essentials

By : Valera Cogut
Book Image

Unity 5 for Android Essentials

By: Valera Cogut

Overview of this book

Table of Contents (14 chapters)
Unity 5 for Android Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accessing the Android sensors and features within Unity 5


Let's discover a little bit more about some Android sensors and features that are shown in the simple code examples later in text.

Acceleration

You can also access the Android acceleration inside Unity. Let's upgrade our previous example, so we can see one more aspect of our Android device. The new piece of code is shown here:

GUILayout.Label("\n\n A C C E L E R A T I O N");
    GUILayout.Label("Input.acceleration = (" + Input.acceleration.x + ", " + Input.acceleration.y + ", " + Input.acceleration.z + ")");

After running this test on your Android device, you will see how acceleration values change very quickly in real time.

Gyroscope

Unity provides gyroscope access on Android devices as shown in the new piece of code. Before using gyroscope, you just need to enable it as shown here:

    Input.gyro.enabled = true;

GUILayout.Label("\n\n G Y R O S C O P E");
    GUILayout.Label("Input.gyro.attitude <<<===>>> " + Input.gyro...