gpt4 book ai didi

c# - unity3d 中的陀螺仪有什么问题(在 google nexus 7 上测试过)

转载 作者:行者123 更新时间:2023-11-30 14:32:22 25 4
gpt4 key购买 nike

我用 c# 编写了一个脚本来测试 unity3d 4.0 中的陀螺仪。并得到信息打击: enter image description here

但是我旋转或移动了我的 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");
}
}


}

最佳答案

您必须启用陀螺仪。您的 Start 方法应如下所示:

void Start ()
{
gyoBool = SystemInfo.supportsGyroscope;

if( gyoBool ) {
gyo1=Input.gyro;
gyo1.enabled = true;
}

Debug.Log (gyoBool.ToString ());
}

此外,您不需要每帧都将陀螺仪分配给“gyo1”(即:从您的更新方法中删除 gyo1=Input.gyro;)。

关于c# - unity3d 中的陀螺仪有什么问题(在 google nexus 7 上测试过),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com