App中使用陀螺仪控制Camera:
using UnityEngine;
using System.Collections;
public class cameraRotation : MonoBehaviour {
void Start()
{
if (Application.platform == RuntimePlatform.Android)
{
Input.gyro.enabled = true;//打开陀螺仪权限
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Input.gyro.updateInterval = 60f;
}
}
void Update()
{
if (!ARManager.instance.attachGyro) return;
this.transform.localRotation = CameraRotation();
//this.transform.localRotation = Quaternion.Slerp(transform.rotation, CameraRotation(), 0.2f);
}
Quaternion CameraRotation()
{
Quaternion input = Input.gyro.attitude;
input = Quaternion.Euler(90, 0, 0) * (new Quaternion(-input.x, -input.y, input.z, input.w));
return input;
}
}