开发者您好,
Unity XR目前只提供了一个获取键值的接口,类似GetKeyDown的逻辑需要开发者自己编写,以下是一个我们封装的简单代码,供您参考:
using UnityEngine;
using UnityEngine.XR;
public class XButton : MonoBehaviour
{
public static bool indexBool = true;
public bool XR_GetKeyDown(XRNode node, InputFeatureUsage<bool> usage)
{
InputDevice device = InputDevices.GetDeviceAtXRNode(node);
bool isDone;
if (device.TryGetFeatureValue(usage, out isDone) && isDone)
{
if (indexBool)
{
indexBool = false;
return true;
}
else
{
return false;
}
}
else
{
indexBool = true;
return false;
}
}
void Update()
{
if (XR_GetKeyDown(XRNode.LeftHand, CommonUsages.primaryButton))
{
Debug.Log("输出");
}
}
}