Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug OVRInput not working

Discussion in 'VR' started by brodycreate, Sep 11, 2023.

  1. brodycreate

    brodycreate

    Joined:
    Dec 7, 2020
    Posts:
    2
    I am making a gun script where you have to shoot a target and then a log appears in the console.
    Here is my script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. public class Gun : MonoBehaviour
    6. {
    7.  
    8.     // Update is called once per frame
    9.     void Update()
    10.     {
    11.         Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 50f, Color.red);
    12.         // This isn't working
    13.         if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger)) {
    14.             Debug.Log("RIndexTrigger Pressed");
    15.             if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out RaycastHit hitinfo, 50f))
    16.             {
    17.             // A hit occurred, handle the hit object or its properties
    18.             Debug.Log("Hit something");
    19.             if (hitinfo.collider.tag == "Target") {
    20.                 Debug.Log("Hit Target!");
    21.             }
    22.             // Handle the hit object as needed
    23.             }
    24.         }
    25.        
    26.     }
    27. }
    28.  
    It doesn't show any errors, but when I aim at the target and press the Right Index Button, nothing happens.
    I am not using the OVRCamera (saw it being used in a Meta post but I don't think it matters).
    I am using Unity 2021.3.15f1 Personal on Windows 11.
    Does anyone have a solution? Thank you in advance.