Skip to content

Instantly share code, notes, and snippets.

@blevok
blevok / GyroCamera.cs
Last active October 2, 2021 06:27 — forked from kormyen/GyroCamera.cs
Gyro camera rotation for Android, tested in Unity 2019.3.2 for API level 28, in landscape left orientation.
// Gyro camera rotation for Android, tested in Unity 2019.3.2 for API level 28, in landscape left orientation.
// Extended to include X and Z axis when claibrating, so you can re-center when looking in any direction, and at a variable speed.
// Attach this script to the parent GameObject of your camera. To re-center, from your main script, call CalibrateAngle, set a bool "letsGoToCenter" to true, a bool "goToCenterSlowly" to true or false, and a string "centerRotSpeed" to slow or fast.
// centerRotSpeed is ignored when goToCenterSlowly is false. You can use "Unity Remote 5" in the Play store to test Android gyro in Unity editor.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GyroCamera : MonoBehaviour
045295911d46eee1abf98d3b7ef465ff2e62f6051df513a4a2eb52461ecac6039784a15da5288fc76788b9a13458dc0074030d61c64495809104d4a4bed98ce8ae