Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to convert fa Script from OVR to XR

Discussion in 'AR/VR (XR) Discussion' started by Mikeramczyk1977, Sep 1, 2020.

  1. Mikeramczyk1977

    Mikeramczyk1977

    Joined:
    Jul 12, 2020
    Posts:
    58
    Hey can anyone help teach me how me to convert this script from running on OVR to work with XR Input??? I am not too knowledgeable, any help????


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class SupermanFlight : MonoBehaviour
    7. {
    8.     public GameObject head;
    9.     public GameObject leftHand;
    10.  
    11.     private float flyingSpeed = 0.8f;
    12.     private bool isFlying = false;
    13.  
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         CheckIfFlying();
    19.         FlyIfFlying();
    20.     }
    21.  
    22.  
    23.     private void CheckIfFlying()
    24.     {
    25.         if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
    26.         {
    27.             isFlying = true;
    28.         }
    29.         if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
    30.         {
    31.             isFlying = false;
    32.         }
    33.     }
    34.  
    35.     private void FlyIfFlying()
    36.     {
    37.         if (isFlying == true)
    38.         {
    39.             Vector3 flyDirection = leftHand.transform.position - head.transform.position;
    40.             transform.position += flyDirection.normalized * flyingSpeed;
    41.         }
    42.     }
    43. }
    44.  
     
  2. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    It is in the XR Input manual under "Accessing input features on an input device"
    Basically shorthand version is: get the right XR device using characteristics and then use TryGetFeatureValue
     
  3. Mikeramczyk1977

    Mikeramczyk1977

    Joined:
    Jul 12, 2020
    Posts:
    58
    I still don't get it.
     
    Butter_Bean likes this.