csharp VR - 更改主导Rift控制器(用于UI点击)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp VR - 更改主导Rift控制器(用于UI点击)相关的知识,希望对你有一定的参考价值。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

/*
this script goes on EACH hand anchor in oculus rift's cameraRig prefab.
then you checkmark isLeft bool in the editor for the leftHandANchor (this controls which half of the code below is used).

It checks every frame to see if the current control has had it's trigger pulled more than half way. 
If so, it goes into the EventSystem and changes the "ray transform" to be this controller.
*/

public class toggleLaserPointer : MonoBehaviour {

    public GameObject tabletControl; // EventSystem for UI. has the pointer we need to change out
    public GameObject laser; //a dummy object with no collider. i just turn this on and off so you can see line from VR hands.
    public bool isLeft = false; //flag for which hand is dominant. set in editor. determines which half of the code below is used.
	
	// Update is called once per frame
	void Update () {
        if (isLeft)
        {
            if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > 0.5)
            {
                Debug.Log("pulled trigger");
                tabletControl.GetComponent<OVRInputModule>().rayTransform = transform;
                laser.SetActive(true);
            }
            else
            {
                laser.SetActive(false);
            }
        }
        else {
            if (OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > 0.5)
            {
                Debug.Log("pulled trigger");
                tabletControl.GetComponent<OVRInputModule>().rayTransform = transform;
                laser.SetActive(true);
            }
            else
            {
                laser.SetActive(false);
            }
        }

    }
}

以上是关于csharp VR - 更改主导Rift控制器(用于UI点击)的主要内容,如果未能解决你的问题,请参考以下文章

如何将oculus rift 虚拟现实VR设备正确的安装

VR规格表出来啦!Rift,Vive,PSVR,Acer和HP

Oculus Rift正式发售,准备好开始迈向VR时代

如何将oculus rift 虚拟现实VR设备正确的安装

如何提高oculus rift画面

神了!React VR使得Oculus Home在Gear VR上运行更快更省电