using UnityEngine;
using System.Collections;
public class GyroController_02: MonoBehaviour
{
private bool gyroBool = true;
private Gyroscope gyro;
private Quaternion rotFix;
void Start ()
{
Transform originalParent = transform.parent;
GameObject camParent = new GameObject ("camParent");
camParent.transform.position = transform.position;
transform.parent = camParent.transform;
camParent.transform.parent = originalParent;
gyroBool = Input.isGyroAvailable;
if (gyroBool)
{
gyro = Input.gyro;
gyro.enabled = true;
if (Screen.orientation == ScreenOrientation.LandscapeLeft)
{
camParent.transform.eulerAngles = new Vector3(90,90,0);
}
else if (Screen.orientation == ScreenOrientation.Portrait)
{
camParent.transform.eulerAngles = new Vector3(90,180,0);
}
if (Screen.orientation == ScreenOrientation.LandscapeLeft)
{
rotFix = new Quaternion(0,0,0.7071f,0.7071f);
}
else if (Screen.orientation == ScreenOrientation.Portrait)
{
rotFix = new Quaternion(0,0,1,0);
}
}
else
{
//LogManager.Instance.Log("NO GYRO");
}
}
void Update ()
{
if (gyroBool)
{
Quaternion camRot = gyro.attitude * rotFix;
transform.localRotation = camRot;
//LogManager.Instance.Log("Angles:" + camRot.eulerAngles);
}
}
}
问题:
android下运行时,Input.gyro. attitude 取出的值一直是(0,0,0,0)
谁知道问题在哪儿,如何解决,请留言指点一下,谢谢
|