59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Android;
|
|
|
|
public class MyCameras : MonoBehaviour
|
|
{
|
|
private Camera myCamera;
|
|
public float rotationSpeed; // 调整这个值来改变旋转速度
|
|
private Quaternion baseRotation;
|
|
|
|
public float trunSpeed;
|
|
public float sensitivity = 1.0f;
|
|
public float smoothing = 5.0f;
|
|
|
|
private float _yaw = 0f;
|
|
private float _pitch = 0f;
|
|
private Vector3 _currentRotation;
|
|
private Vector3 _smoothVelocity = Vector3.zero;
|
|
|
|
public bool isZhuanXiang=true;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
if (!Permission.HasUserAuthorizedPermission("android.permission.BODY_SENSORS"))
|
|
{
|
|
Permission.RequestUserPermission("android.permission.BODY_SENSORS");
|
|
}
|
|
if (!SystemInfo.supportsGyroscope)
|
|
{
|
|
Debug.LogError("设备不支持陀螺仪");
|
|
this.enabled = false;
|
|
return;
|
|
}
|
|
|
|
Input.gyro.enabled = true;
|
|
Quaternion gyroRotation = Input.gyro.attitude;
|
|
transform.rotation = new Quaternion(gyroRotation.x, gyroRotation.y, -gyroRotation.z, -gyroRotation.w);
|
|
}
|
|
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Time.time < 5)
|
|
{
|
|
Input.gyro.enabled = true;
|
|
Quaternion gyroRotation = Input.gyro.attitude;
|
|
transform.rotation = new Quaternion(gyroRotation.x, gyroRotation.y, -gyroRotation.z, -gyroRotation.w);
|
|
}
|
|
else
|
|
{
|
|
isZhuanXiang=false;
|
|
}
|
|
}
|
|
|
|
}
|