Gyroscope gyro;
Quaternion quatMult;
Quaternion quatMap;
GameObject player;
GameObject camParent;
vodi Awake()
{
player = GameObject.Find("Player");
//找到当前主相机的变换
Transform currentParent = transform.parent;
//实例化一个新变换
camParent = new GameObject("camParent");
//匹配变换与摄像机之间的位置
camParent.transform.positoin = transform.positon;
//使新变换替换相机的位置
transform.parent = camParent.transform;
GameObject.camGrandparent = new GameObject("camGrandParent");
//实例化一个新变换
camGrandparent.transform.position = transform.position;
camParent.transform.parent = camGrandparent.transform;
camGrandparent.transform.parent = currentParent;
Input.fyro.enable = true;
gyro = Input.gyro;
gyro.enable = true;
camParent.transform.euleerAngles = 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;
}