using UnityEngine;
using System.Collections;
public class Gyro : MonoBehaviour {
Gyroscope gyro;
Quaternion quatMult;
Quaternion quatMap;
GameObject player;
GameObject camParent;
void Awake() {
player = GameObject.Find("Player");
Transform currentParent = transform.parent;
camParent = new GameObject("camParent");
camParent.transform.position = transform.position;
transform.parent = camParent.transform;
GameObject camGrandparent = new GameObject("camGrandParent");
camGrandparent.transform.position = transform.position;
camParent.transform.parent = camGrandparent.transform;
camGrandparent.transform.parent = currentParent;
gyro = Input.gyro;
gyro.enabled = true;
camParent.transform.eulerAngles = new Vector3(90,0, 0);
quatMult = new Quaternion(0, 0, 1, 0);
}
void Update() {
quatMap = new Quaternion(gyro.attitude.x, gyro.attitude.y, gyro.attitude.z,gyro.attitude.w);
Quaternion qt=quatMap * quatMult;
transform.localRotation =qt;
}
}
陀螺仪控制物体
最新推荐文章于 2023-04-13 10:00:00 发布