I’m trying to add a button to allow the player to interact with objects in my game using the E key, but for some reason unity isn’t recognizing the input.
I’ve followed the existing structure of the first person core sample and done the following:
- Added the input action to the existing “Player” actionmap where all other inputs are stored (move, look, jump, sprint)
- Edited the StarterAssetsInput.cs, copied all code for the “jump” input while renaming anything labeled “jump” to “interact”
public bool interact;
////////
public void onInteract(InputValue value)
{
InteractInput(value.isPressed);
}
////////
public void InteractInput(bool newInteractState)
{
interact = newInteractState;
}
- Created a new function to test the interaction
private void DoInteract()
{
if (_input.interact)
{
UnityEngine.Debug.Log("Interacted, but nothing to interact with");
}
}
- Added that function to the “Update” function:
private void Update()
{
JumpAndGravity();
GroundedCheck();
Move();
DoInteract();
}
This seemingly did nothing, when i tested the key nothing happened. nothing in the log.
So I tried changing the “jumpandgravity” from _input.jump to trigger the action to _input.interact. This removed the ability to jump but did not show anything in the debug log.
So i changed the actual button for the jump action to E and tested again (after changing back to input.jump) and that allowed me to jump using the E button.
Why is _input.interact not working??