Search Unity

Question How to turn on raycast from controllers when it hits a certain game object through C#

Discussion in 'XR Interaction Toolkit and Input' started by LuigiNicastro, Feb 15, 2022.

  1. LuigiNicastro

    LuigiNicastro

    Joined:
    Feb 7, 2018
    Posts:
    34
    I currently have a script that makes it so my Interactor Line Visual only turns on when a button is pressed in code. I wanted to know if someone knew how to make it so it could also turn on automatically when hitting UI in the scene without having to press a button.

    upload_2022-2-15_15-10-2.png
     
  2. chris-massie

    chris-massie

    Unity Technologies

    Joined:
    Jun 23, 2020
    Posts:
    231
    If you are referring to Canvas UI elements when you mention hitting UI in the scene, you can call GetTrackedDeviceModel to get the pointer id of the XRRayInteractor, and then pass that id to IsPointerOverGameObject.

    You will need to update your
    TeleportController
    behavior to serialize a reference to the
    XRUIInputModule
    on the EventSystem GameObject in your scene or find it by casting the
    EventSystem.current
    to that class.