我在 c# 中编写了一个脚本来测试 unity3d 4.0 中的陀螺仪。并获得信息打击:
但是我旋转或移动我的 google nexus 7。每个参数都保持“0”;我不知道为什么。
任何人都可以帮助我吗?
这是我的代码:
using UnityEngine;
using System.Collections;
public class gyroscope : MonoBehaviour
{
private Gyroscope gyo1;
private bool gyoBool;
//private Quaternion rotFix;
// Use this for initialization
void Start ()
{
gyoBool = SystemInfo.supportsGyroscope;
Debug.Log (gyoBool.ToString ());
}
// Update is called once per frame
void Update ()
{
gyo1=Input.gyro;
}
void OnGUI ()
{
if (gyoBool != null)
{
GUI.Label (new Rect (10, Screen.height / 2 - 50, 100, 100), gyoBool.ToString ());
if (gyoBool == true)
{
GUI.Label (new Rect (10, Screen.height / 2-100, 500, 100), "gyro supported");
GUI.Label (new Rect (10, Screen.height / 2, 500, 100), "rotation rate:" + gyo1.rotationRate.ToString ());
GUI.Label (new Rect (10, Screen.height / 2 + 50, 500, 100), "gravity: " + gyo1.gravity.ToString ());
GUI.Label (new Rect (10, Screen.height / 2 + 100, 500, 100), "attitude: " + gyo1.attitude.ToString ());
GUI.Label (new Rect (10, Screen.height / 2 + 150, 500, 100), "type: " + gyo1.GetType ().ToString ());
}
else
GUI.Label (new Rect (Screen.width / 2 - 100, Screen.height / 2, 100, 100), "not supported");
}
}
}