Milky Way
Unity AR Gyroscope Sensors

Gyroscope Sensor

Integrating the gyroscope sensor in our phones

Gyroscope

Create a new script in Unity named Gyroscope.cs. Attach your script to a cube or 3D object that is in your scene. It is important to attach your Unity script after you create it. It will throw errors if you have a script that is not attached.

Then, copy and paste the following code into your Gyroscope.cs script. The code will also be found in the following repository https://github.com/debbieyuen/ctin583-fa24-hw/. To access this code on your own fork, click on the sync changes button on your forked repository.

Gyroscope.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Gyroscope : MonoBehaviour
{
 
    // Start is called before the first frame update
    void Start()
    {
        Input.gyro.enabled = true;
    }
 
    // Update is called once per frame
    void Update()
    {
        Debug.Log(Input.gyro.attitude);
        transform.rotation = Input.gyro.attitude;
    }
}

On this page