I’m trying to understand the easiest way to read inputs from the new Input System in code in a single class.
I want to read all the player input in a single class (called from within Update()) and then process it later down the line in Update() and FixedUpdate() respectively).
For instance, I would have something like this (just a simple pseudocode example) with the old input system:
private Vector2 playerMovement = Vector2.zero;
private bool playerAttacking = false;
void GetPlayerInput()
{
playerMovement.x = Input.GetAxisRaw("Horizontal");
playerMovement.y = Input.GetAxisRaw("Vertical");
if (Input.GetKey("Attack"))
playerAttacking = true;
else
playerAttacking = false;
}
How do I implement something like this with the new Input System and which Behaviour (Send Messages, Broadcast Messages, Invoke Unity Events or Invoke C Sharp Events) would I need for it?
The two former ones all rely on multiple classes which is messy and not what I’m looking for (a single class to handle reading all input with a secondary class processing the player movement).
Then the Invoke Unity Events behaviour, although apparently suggested, relies almost entirely on Unity Editor side references which are very detached from the code side of the project, break easily (references) and just aren’t accessible through code properly.
That leaves me (as far as I understand the new Input System currently) only with the option to go for Invoke C Sharp Events. The Generate C# Class function generates a C# source file that seems to overtly complicate things by taking everything into account and none of the code or any examples I’ve been able to find online have suggested a way of doing things in a fashion similar to my code example above.
I might not be understanding the new Input System correctly, which is entirely possible as I’m just a hobbyist programmer, but I’m sure there must be some sort of a reasonably simple and robust way of just reading the status of the inputs based on their Action names.
Any help would be immensely appreciated, as the new Input System is still relatively new, especially in terms of available tutorials and documentation of clarity, thanks!