- Home /
Input.getKeyDown alternative for XR Devices
Hello! I am trying to make a sword that activates a certain effect after a button has been pressed. This is supposed to be a mod for a game, so i used unitys XR tools to find out when a button has been pressed. That works, but it returns when the button has been pressed AND released, which activates my sword effect and deactivates it as soon as i let go of the button. Here's my code:
if (rightInput.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primaryButton, out gripped) && gripped && !wasPressed)
{
wasPressed = true;
Deactivate();
}
else if (rightInput.TryGetFeatureValue(UnityEngine.XR.CommonUsages.primaryButton, out gripped) && gripped && wasPressed)
{
wasPressed = false;
Activate();
}
I'm looking for an alternative Method that is like "GetKeyDown", where i press a button and only the pressing of the button is recognized, not the release. Thanks in advance!
Answer by adhochero · Aug 17, 2020 at 01:35 PM
as far as i know xr doesnt check it for you. if you want a getkeydown act-alike, you'll have to check triggers states per frame and comparing it yourself, something like this:
if(inputNotDownlastFrame && IsDownThisFrame)
{
bool inputdownthisframe = true;
}
else
{
inputdownthisframe = false;
}