C# Unity XR VR输入和GetDeviceWithCharacteristics语法可能存在问题?

C# Unity XR VR输入和GetDeviceWithCharacteristics语法可能存在问题?,c#,unity3d,virtual-reality,C#,Unity3d,Virtual Reality,我不得不注释掉我的一堆代码,但归结起来有两个错误。问题似乎出在使用“GetDevicesWithCharacteristics”的行上,因为这也是错误所在,但我检查了文档,结果似乎不错。我还检查了上面的行,我不确定“LeftHandedController;”我在事后加上了这句话,是为了跟在文档后面,这其实不是问题所在 我没有经验,所以如果这是一个简单的错误,请原谅我 using UnityEngine.Events; using UnityEngine.XR; using System.C

我不得不注释掉我的一堆代码,但归结起来有两个错误。问题似乎出在使用“GetDevicesWithCharacteristics”的行上,因为这也是错误所在,但我检查了文档,结果似乎不错。我还检查了上面的行,我不确定“LeftHandedController;”我在事后加上了这句话,是为了跟在文档后面,这其实不是问题所在

我没有经验,所以如果这是一个简单的错误,请原谅我


using UnityEngine.Events;
using UnityEngine.XR;

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

public class controlerInputScript : MonoBehaviour
{
    GameObject gameObjectToMove;
    public int scale = 3;


    var leftHandedControllers = new List<UnityEngine.XR.InputDevice>();
    InputDeviceCharacteristics leftcontrollerdesiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller, leftHandedControllers;
    InputDevices.GetDevicesWithCharacteristics(XR.InputDeviceCharacteristics leftcontrollerdesiredCharacteristics, List<InputDevice> leftHandedControllers);


    // var rightHandedControllers = new List<UnityEngine.XR.InputDevice>();
    // var rightcontrollerdesiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Right | UnityEngine.XR.InputDeviceCharacteristics.Controller;
    // UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(rightcontrollerdesiredCharacteristics, rightHandedControllers);


    // if (leftHandedControllers > 1) || (rightHandedControllers >1){
    //     Debug.Log("DEBUG: ERROR: More than one Left or Right handed controller detected!")
    // }

    //assign Controlllers
    InputDevice leftController = leftHandedControllers[0];
    //InputDevice rightController = rightHandedControllers[0];

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // // Update is called once per frame
    void Update()
    {
        Vector3 p = this.transform.position;
        float leftTriggerState;
        if (leftController.TryGetFeatureValue(CommonUsages.trigger, out leftTriggerState)){
            p.y = scale * leftTriggerState;
            gameObjectToMove.transform.position = p;
        }
     
    //     float rightGripState;
    //     if (rightController.TryGetFeatureValue(CommonUsages.grip, out rightGripState)){
    //         p.x = scale* rightGripState;
    //         gameObjectToMove.transform.position = p;
    //     }
    }
}

提前谢谢你的帮助

我说的是那些台词

var leftHandedControllers = new List<UnityEngine.XR.InputDevice>();
InputDeviceCharacteristics leftcontrollerdesiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller, leftHandedControllers;
InputDevices.GetDevicesWithCharacteristics(XR.InputDeviceCharacteristics leftcontrollerdesiredCharacteristics, List<InputDevice> leftHandedControllers);
在第二行,你确定吗

,左撇子控制器

因为此语法不正确,也没有任何语义

在第三行中,您试图在参数中执行什么操作!您正在重新定义函数参数中以前的变量

我相信您的代码应该是:

var leftHandedControllers = new List<UnityEngine.XR.InputDevice>();
InputDeviceCharacteristics leftcontrollerdesiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller;
InputDevices.GetDevicesWithCharacteristics(leftcontrollerdesiredCharacteristics, leftHandedControllers);

我做了更多的检查,确定错误来自GetDeviceWithCharacteristics行。我还可以使用另一种方法来复制错误,即获取控制器GetDevicesWithRole。当我取消注释它们时,两个错误都发生了两次。这似乎是一个语法错误,但据我所知,我似乎在遵循文档。好的,如果您可以共享此文档,检查您是否遗漏了一些内容可能会有所帮助
var leftHandedControllers = new List<UnityEngine.XR.InputDevice>();
InputDeviceCharacteristics leftcontrollerdesiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller;
InputDevices.GetDevicesWithCharacteristics(leftcontrollerdesiredCharacteristics, leftHandedControllers);