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
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 5 for Android Essentials

You're reading from   Unity 5 for Android Essentials A fast-paced guide to building impressive games and applications for Android devices with Unity 5

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781784399191
Length 200 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Valera Cogut Valera Cogut
Author Profile Icon Valera Cogut
Valera Cogut
Arrow right icon
View More author details
Toc

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...
You have been reading a chapter from
Unity 5 for Android Essentials
Published in: Aug 2015
Publisher:
ISBN-13: 9781784399191
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