I am new to using the new input system.
I am wondering how to do something similar to Input.GetKeyDown() ?
I just want the variable isKPressedThisFrame to be true at the frame I press down the key, but
the code followed will not set isKPressedThisFrame to false if I am holding down the key ( the inputAction.cancelled event will not be triggered if I don’t release the key)
float isKPressedThisFrame;
public void OnKPress(){
isKPressedThisFrame = true;
}
public void OnKRelease(){
isKPressedThisFrame = false;
}
public void OnEnable(){
inputAction.Performed += OnKPress;
inputAction.Cancelled += OnKRelease;
}
For GetKeyDown the documentation says you should use
Keyboard.current.spaceKey.wasPressedThisFrame
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Migration.html#unityengineinputgetkeydownhttpsdocsunity3dcomscriptreferenceinputgetkeydownhtml
I dont think I understand your question correctly because from your code Id expect isKPressedThisFrame to be true as long as you hold the button. Why should cancelled be called if it hasnt been released?
But if you say you only want the first frame you could do something like this
private void Update(){
if (isKPressedThisFrame)
isKPressedThisFrame = false;
}
Haven’t tested it, maybe it needs to run as a Late Update