unity3d中怎么实现让摄像机跟随手机的方向改变而改变
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity3d中怎么实现让摄像机跟随手机的方向改变而改变相关的知识,希望对你有一定的参考价值。
参考技术A 用陀螺仪,非常方便,几行代码!using UnityEngine;
using System.Collections;
// 陀螺仪
public class GyroscopeComponent: MonoBehaviour
public float interval = 0.2f;
Gyroscope gyro;
Quaternion quatMult;
Quaternion quatMap;
//UILabel ul;
public GameObject camParent;
private Vector3 qtBack;
private bool bDown = true;
void Start()
// find the current parent of the camera's transform
// instantiate a new transform
// match the transform to the camera position
camParent.transform.position = transform.position;
// make the new transform the parent of the camera transform
transform.parent = camParent.transform;
gyro = Input.gyro;
gyro.enabled = true;
camParent.transform.eulerAngles = new Vector3(90, 0, 0);
quatMult = new Quaternion(0, 0, 1, 0);
qtBack = transform.localRotation.eulerAngles;
void Update()
quatMap = new Quaternion(gyro.attitude.x, gyro.attitude.y, gyro.attitude.z, gyro.attitude.w);
Quaternion qt = quatMap * quatMult;
transform.localRotation = qt;
参考技术B 不是调用陀螺仪? 参考技术C 你能得到手机的方向么?追问
已经解决,找到了相关脚本
以上是关于unity3d中怎么实现让摄像机跟随手机的方向改变而改变的主要内容,如果未能解决你的问题,请参考以下文章