Search Unity

How can i switch the laserpointer (UIHelper) from right to the left controller?

Discussion in 'VR' started by V-J, Jul 9, 2019.

  1. V-J

    V-J

    Joined:
    Apr 1, 2015
    Posts:
    31
    When adding the UIHelper prefab from the OculusIntergration, it directly assigns it to the right controller. How can i switch it to the left controller?
    Do need to change the HandedInputSelector.cs?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.EventSystems;
    4. using UnityEngine.UI;
    5. using System;
    6.  
    7. public class HandedInputSelector : MonoBehaviour
    8. {
    9.     OVRCameraRig m_CameraRig;
    10.     OVRInputModule m_InputModule;
    11.  
    12.     void Start()
    13.     {
    14.         m_CameraRig = FindObjectOfType<OVRCameraRig>();
    15.         m_InputModule = FindObjectOfType<OVRInputModule>();
    16.     }
    17.  
    18.     void Update()
    19.     {
    20.         if (OVRInput.GetActiveController() == OVRInput.Controller.LTouch)
    21.         {
    22.             SetActiveController(OVRInput.Controller.LTouch);
    23.         }
    24.         else
    25.         {
    26.          SetActiveController(OVRInput.Controller.RTouch);
    27.         }
    28.  
    29.     }
    30.  
    31.      void SetActiveController(OVRInput.Controller c)
    32.     {
    33.         Transform t;
    34.         if(c == OVRInput.Controller.LTouch)
    35.         {
    36.             t = m_CameraRig.leftHandAnchor;
    37.         }
    38.         else
    39.         {
    40.             t = m_CameraRig.rightHandAnchor;
    41.         }
    42.         m_InputModule.rayTransform = t;
    43.     }
    44. }
     
    Last edited: Jul 9, 2019