Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

[solved] Gyroscope Controller

Discussion in 'VR' started by lamyikting, Jul 9, 2019.

  1. lamyikting

    lamyikting

    Joined:
    Jun 20, 2019
    Posts:
    3
    [problem solved, thanks everyone!]
     

    Attached Files:

    Last edited: Jul 10, 2019
  2. lamyikting

    lamyikting

    Joined:
    Jun 20, 2019
    Posts:
    3
    This is my gyroscope code.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Gyro : MonoBehaviour
    {

    private bool gyroEnabled;
    public GameObject CameraMover;
    private Gyroscope gyro;
    private Quaternion rot;


    // Start is called before the first frame update
    private void Start()
    {

    CameraMover.transform.position = transform.position;
    gyroEnabled = EnableGyro();
    }

    private bool EnableGyro(){
    if (SystemInfo.supportsGyroscope){
    gyro = Input.gyro;
    gyro.enabled = true;

    CameraMover.transform.rotation = Quaternion.Euler(90f, 90f, 0f);
    rot = new Quaternion(0, 0, 1, 0);
    return true;
    }
    return false;
    }
    // Update is called once per frame
    void Update()
    {
    if (gyroEnabled){
    transform.localRotation = gyro.attitude * rot;
    }
    }
    }

     
unityunity