美文网首页
Unity 陀螺仪控制摄像机360度旋转

Unity 陀螺仪控制摄像机360度旋转

作者: 玄策丶 | 来源:发表于2020-07-27 15:12 被阅读0次

脚本挂到摄像机上

/***********************
 * 遇见你的眉眼,如清风明月。
 * 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;
    }
}

相关文章

网友评论

      本文标题:Unity 陀螺仪控制摄像机360度旋转

      本文链接:https://www.haomeiwen.com/subject/auoiqktx.html