I'm trying to learn new Unity input system. In previous Unity input system,
if (Input.GetKeyDown("f"))
//do something when key 'f' is pressed
if (Input.GetKeyDown("g"))
//do something when key 'g' is pressed
if (Input.GetKeyDown("h"))
//do something when key 'h' is pressed
if (Input.GetKeyDown("j"))
//do something when key 'j' is pressed
would do any defined actions along keypress of f,g,h,j.
In new Unity input system, there is InputAction, which I can define Action Maps, Actions, and Properties. I can then implement functions as below, that can be called from PlayerInput under inspector of player object.
public void OnKey_F(InputAction.CallbackContext context)
{
if (context.started)
Debug.Log("Pressed F");
}
public void OnKey_G(InputAction.CallbackContext context)
{
if (context.started)
Debug.Log("Pressed G");
}
public void OnKey_H(InputAction.CallbackContext context)
{
if (context.started)
Debug.Log("Pressed H");
}
public void OnKey_J(InputAction.CallbackContext context)
{
if (context.started)
Debug.Log("Pressed J");
}
Is this right way to do the same funtion as above, under new Unity input system? The tutorials I found were mostly for WASD movement, which I already figured out how it works(2d vector). However, I'm not sure for this case which requires multiple keys for multiple functions.