Search Unity

Question Convert ovr script to unity XR

Discussion in 'XR Interaction Toolkit and Input' started by Zer0_obscura, Jan 12, 2021.

  1. Zer0_obscura

    Zer0_obscura

    Joined:
    Nov 20, 2013
    Posts:
    13
    Hello

    so I have this script. It works great on the old ovr rig. Just assign it to the rig, and drag in the mid camera part and the left hand.

    How do I go about turning this to a Unity XR script? Also, would I even be able to attach to the highest part of the xr rig, and have it work like the ovr rig initially did? Sorry, im a noob.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Fly : MonoBehaviour
    {
    public GameObject head;
    public GameObject leftHand;

    private float flyingSpeed = .5f;
    private bool isFlying = false;
    // Update is called once per frame
    void Update()
    {
    CheckIfFlying();
    FlyIfFlying();
    }
    private void CheckIfFlying()
    {
    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
    {
    isFlying = true;
    }
    if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
    {
    isFlying = false;
    }
    }
    private void FlyIfFlying()
    {
    if (isFlying == true)
    {
    Vector3 flyDirection = leftHand.transform.position - head.transform.position;
    transform.position += flyDirection.normalized * flyingSpeed;
    }
    }
    }
     

    Attached Files:

    • Fly.cs
      File size:
      1,008 bytes
      Views:
      268
  2. TymNetwork

    TymNetwork

    Joined:
    Jan 16, 2014
    Posts:
    84
    I am wondering this too