Last active
August 29, 2015 14:00
-
-
Save poemdexter/11022613 to your computer and use it in GitHub Desktop.
phone tilt left/right to move thing left/right
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TiltController : MonoBehaviour | |
{ | |
public float speed; | |
void Update() | |
{ | |
Vector3 dir = Vector3.right * Input.acceleration.x; | |
if (dir.sqrMagnitude > 1) | |
dir.Normalize(); | |
transform.Translate(dir * Time.deltaTime * speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment