Accelerometer Input

Checked with version: 4.3

-

Difficulty: Beginner

Modern mobile devices have a built in accelerometer which allows them to know their orientation in 3D space. We can use the devices orientation to control objects in our games. In this video you will learn about the accelerometer and how to use it in a scene.

Accelerometer Input

Beginner Mobile & Touch

AccelerometerInput

Code snippet

using UnityEngine;
using System.Collections;

public class AccelerometerInput : MonoBehaviour 
{
    void Update () 
    {
        transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
    }
}
#pragma strict

function Update () 
{
    transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
}
import UnityEngine
import System.Collections


public class AccelerometerInput(MonoBehaviour):

    private def Update():
        transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z)
Multi Touch Input
Pinch to Zoom

Related documentation

Mobile & Touch

Getting Input

  1. Multi Touch Input
  2. Accelerometer Input
  3. Pinch to Zoom

App Stores

  1. How to submit to the iOS App Store (overview)
Got it

We use cookies to ensure that we give you the best experience on our website. Click here for more information.