Hi, I’m working on a game, where the user picks up trash in Trash cans and dumps them into a Trash Truck. I’ve decided to convert over to the New Input System, for multiple controller support, and whatnot.
However, I’ve run into a problem with an asset I’m using, called First Person All-in-One.
I can’t seem to be able to get it to work so that it moves the character when the player presses a button. It used to use Input.GetButtonDown for this, I’m using (in this case, the name of the action is jumpKey,), jumpKey == 1. It will detect these inputs in the script, but it doesn’t seem to do anything with it.
If anyone has any ideas, please, let me know!
Thanks.
Supposing you know how to work with the input action asset, you need to create a new action called however you want, lets say “Walk”, set the action type to Button and adding a binding to that action corresponding to your jumpkey. Add the “press” interaction to the “Walk” Action and set the trigger behaviour to “press and release”.
Next you need to get that input to your script. The easiest way to do so (but not the only) is to add the “Player Input” component to the gameobject you need to be moving (which i guess it’s the Player), set the right InputActionAsset and then decide the behaviour.
I would suggest using “Send Messages”, but the choice is yours. If you use “Send Messages” or “Broadcast Messages”, you can directly receive the input in any other script attached to that same gameobject.
In this case, in your script use this function:
bool canWalk = false; //you need a variable to store the input
void OnWalk(InputValue val) {
canWalk = val.isPressed;
}
Remember to write using UnityEngine.InputSystem; at the beginning of your script
now you have a variable called canWalk, wich is basically equivalent to the GetKeyDown(...) method of the old Input System, so you can simply use if(canWalk) to check if the key is pressed
Note that if you decide to name the action differently, you need to change the function name from OnWalk(…) to Onwhatever name you gave to the action