Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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:
    73
    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
  2. unity_QjPE1Ur0mLEAlA

    unity_QjPE1Ur0mLEAlA

    Joined:
    Jun 8, 2019
    Posts:
    1
    I had the same problem with, so that it always sets to the rightHandAnchor instead of the leftHandAnchor.
    If you want to make a fix/static RayTransform position, you can just comment the update function out.
     
  3. prashantagent47

    prashantagent47

    Joined:
    Jan 2, 2016
    Posts:
    5

    void Update()
    {
    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger,OVRInput.Controller.RTouch))
    {
    SetActiveController(OVRInput.Controller.RTouch);
    }

    if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch))
    {
    SetActiveController(OVRInput.Controller.LTouch);
    }
    }


    Replace Update code of HandedInputSelector.cs and it starts working for both controllers
     
    aarongao1109 likes this.
  4. FuzzyOnion

    FuzzyOnion

    Joined:
    Aug 22, 2014
    Posts:
    31
    Hmm... I'm running into the same problem and the above code didn't work for me...