I’m using Unity’s new input system, and currently facing a problem with WasPressedThisFrame function.
using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerInputHandler : MonoBehaviour
{
private PlayerInput playerInput;
private Player player;
private Timer jumpInputBufferTimer;
[HideInInspector] public Controls controls;
public Vector2 movementInput { get; private set; }
public int normInputX { get; private set; }
public int normInputY { get; private set; }
public bool jumpInput { get; private set; }
public bool jumpInputActive { get; private set; }
// etc...
private void Awake()
{
controls = new Controls();
playerInput = GetComponent<PlayerInput>();
player = GetComponent<Player>();
jumpInputBufferTimer = new Timer(player.playerData.jumpInputBufferTime);
jumpInputBufferTimer.timerAction += InactiveJumpInput;
}
private void Update()
{
jumpInputBufferTimer.Tick();
Debug.Log(controls.InGame.Attack.WasPressedThisFrame()); // -> always returns false
}
public void OnMoveInput(InputAction.CallbackContext context)
{
movementInput = context.ReadValue<Vector2>();
actualInputX = Mathf.RoundToInt(movementInput.x);
normInputX = preventInputX ? fixedInputX : actualInputX;
normInputY = Mathf.RoundToInt(movementInput.y);
}
public void OnJumpInput(InputAction.CallbackContext context)
{
if (context.started)
{
jumpInput = true;
jumpInputActive = true;
jumpInputBufferTimer.StartSingleUseTimer();
}
if (context.canceled)
{
jumpInput = false;
}
}
// etc...
}
Above is my code, and I want to change my way of getting the input from using CallbackContext to WasPressedThisFrame. It’s simply because using context stores input results and sometimes causes problems related to controls. But as I wrote in the code it seems like WasPressedThisFrame is not doing its job.
Can anybody help? Thank you in advance.