Search Unity

  1. Unity 2019.2 is now released.
    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;
    }
    }
    }