using UnityEngine;
using System.Collections;

public class GyroTest : MonoBehaviour {

	public bool updatePosition;
	public bool updateRotation;
	public float gryoMovementFactor;

	// Use this for initialization
	void Start () {
		Input.gyro.enabled = true;
		Input.gyro.updateInterval = 0.01f;
	}
	
	// Update is called once per frame
	void Update () {
		if(updatePosition)
		{
			var userAcc = Input.gyro.userAcceleration;
//			var tempY = userAcc.y;
//			userAcc.y = -userAcc.z;
//			userAcc.z = tempY;
			transform.position += userAcc * gryoMovementFactor;
		}
		if(updateRotation)
		{
			var inverseGyro = Quaternion.Inverse(Input.gyro.attitude);
			var tempZ = inverseGyro.z;
			inverseGyro.z = inverseGyro.y;
			inverseGyro.y = tempZ;
			transform.rotation = inverseGyro;
		}
	}
}
