Realize gyroscope function, rotate device, camera follow rotation
Drag the following script to the camera, pack it as an Android or iOS project, and test on the real machine
You should put some models in the scene, or you won't see the effect.
Using Unityengine;
Using System.Collections;
public class Aaa:monobehaviour {Private Const float lowpassfilterfactor = 0.2f;
protected void Start () {//Set the device gyroscope on/off state, the gyroscope function must be set to true Input.gyro.enabled = true;
Get the device of gravitational acceleration vector Vector3 devicegravity = Input.gyro.gravity;
The rotation speed of the device, the return result is the rotational speed of the x,y,z axis, the unit is (radians/sec) Vector3 rotationvelocity = Input.gyro.rotationRate;
Obtain more precise rotational Vector3 rotationVelocity2 = Input.gyro.rotationRateUnbiased;
Set up a gyroscope update retrieval time, that is, 0.1 seconds update Input.gyro.updateInterval = 0.1f;
Obtain the acceleration Vector3 acceleration = Input.gyro.userAcceleration of the device after removing the acceleration of gravity; The protected void Update () {//input.gyro.attitude return value is of type quaternion, that is, the device rotates Euler angle transform.
rotation = Quaternion.slerp (transform.rotation, Input.gyro.attitude, lowpassfilterfactor); } void Ongui () {GUI. Label (New RecT (A, M, v), "Label:" + input.gyro.attitude.x + "" + Input.gyro.attitude.y + "" + Input.gyro.att
ITUDE.Z); }
}