Last active
August 31, 2016 05:15
-
-
Save tsubaki/634823da94a979c4fcac to your computer and use it in GitHub Desktop.
ジャイロを回す。
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 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