- Home /
Question by
Caidek · May 27, 2020 at 06:55 PM ·
c#inputunity input
New Unity Input System Delay on Keyboard
Hello all,
I am new to using the new unity input 1.0 system and have been having an issue with it. I have code that polls for if the keyboard button is being held or not, which works, however it appears to only fire on 1 of every 5-10 key presses.
Example:
Player presses F key - attack fires, player holds F key - stomp attack fires
Player presses F key - nothing happens, Player presses F key - nothing happens, Player holds F key - nothing happens, Player presses F key - attack fires.
Can someone take a look and see if I am doing something wrong?
Input actions file
Input c# script
private void ProcessPlayerInput()
{
// Update horizontal inputs
horizontal += controls.Player.Move.ReadValue<float>();
horizontalRaw += horizontal;
// Clamp horizontal to -1, 0, 1 as opposed to horizontalRaw which is not clamped
horizontal = Mathf.Clamp(horizontal, -1f, 1f);
// Check for jump inputs
jumpPressed = jumpPressed || controls.Player.Jump.triggered;
// Poll for attack inputs
controls.Player.Attack.performed +=
ctx =>
{
if (ctx.interaction is HoldInteraction)
{
// Attack button being held = perform stomp attack
stompAttack = true;
}
else
{
// Attack button was only pressed = basic attack
basicAttack = true;
}
};
}
Originally, as per the demo scripts in (SimpleControls demo that comes with the package) it had the code block in the Awake() method, however this doesn't seem correct to me so I have moved it into the Update() method instead.
Comment