脚本挂到摄像机上
/***********************
* 遇见你的眉眼,如清风明月。
* Title: "陀螺仪控制摄像机360°旋转 "
* Func:
* -
* UsedBy:
* Date: 2020
* Author: XC
* Version: 1.0
* Description:
***********************/
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()
{
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;
}
}
网友评论