Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 31, 2016 05:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/634823da94a979c4fcac to your computer and use it in GitHub Desktop.
Save tsubaki/634823da94a979c4fcac to your computer and use it in GitHub Desktop.
ジャイロを回す。
using UnityEngine;
using System.Collections;
public class Gylo : MonoBehaviour
{
#if UNITY_EDITOR
[SerializeField, Range(1, 3)]
float speed = 1;
private float horizontal,vertical;
Quaternion rotation;
void Start()
{
rotation = transform.rotation;
}
void LateUpdate ()
{
horizontal += Input.GetAxis("Horizontal");
vertical += Input.GetAxis("Vertical");
var rot = rotation;
rot *= Quaternion.AngleAxis(horizontal, Vector3.up);
rot *= Quaternion.AngleAxis(vertical, Vector3.right);
transform.rotation = rot;
}
#elif UNITY_ANDROID
void Start ()
{
Input.gyro.enabled = true;
}
void Update ()
{
var attitude = Input.gyro.attitude;
Quaternion rotation = new Quaternion (-attitude.x, -attitude.z, -attitude.y, attitude.w) * Quaternion.Euler (90f, 0f, 0f);
transform.localRotation = rotation;
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment