Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么';unity3d中的陀螺仪有什么问题(在谷歌Nexus7上测试过)_C#_Unity3d_Gyroscope - Fatal编程技术网

C# 什么';unity3d中的陀螺仪有什么问题(在谷歌Nexus7上测试过)

C# 什么';unity3d中的陀螺仪有什么问题(在谷歌Nexus7上测试过),c#,unity3d,gyroscope,C#,Unity3d,Gyroscope,我用c#编写了一个脚本来测试unity3d 4.0中的陀螺仪。 并获得信息: 然而,我旋转或移动我的谷歌Nexus7。每个参数保持“0”;我不知道为什么 有人能帮我吗 这是我的密码: using UnityEngine; using System.Collections; public class gyroscope : MonoBehaviour { private Gyroscope gyo1; private bool gyoBool; //private Qu

我用c#编写了一个脚本来测试unity3d 4.0中的陀螺仪。 并获得信息:

然而,我旋转或移动我的谷歌Nexus7。每个参数保持“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");
        }
    }


}  

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

void Start ()
{
    gyoBool = SystemInfo.supportsGyroscope;

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

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

另外,您不需要在每一帧都将陀螺仪指定给“gyo1”(即:从更新方法中删除gyo1=Input.gyro)。

您可以尝试将所有对旋转率、重力和姿态的调用更改为
ToString(“F4”)
?然后看看这是否提供了一些输出。我不知道SDK,但是:陀螺仪是“受支持的”;它是“已启用的”吗?支持并不一定意味着该功能处于活动状态。当作为toString(“F4”)执行时,它看起来像是(0.0000,0.0000,0.0000)@Bartmy的逻辑是:如果(陀螺仪已启用),则{print“supported”}不确定答案抱歉,但有一件事是您不应该在更新中分配陀螺仪,因为这意味着您将在每一帧重新分配它。在这个例子中,你应该使用唤醒或启动。嘿,酷家伙。它工作了,并且计算出了我需要的参数,非常感谢。我有完全相同的问题,我已经仔细检查了:陀螺在初始化时被支持并启用,但姿态始终为零。有没有关于问题根源的猜测?