Hey, I’ve been experimenting with the new input system and i can’t seem to figure out how to detect a continuous action for the current local player (as in: press and hold to fire action in a local multiplayer game).
I’ve made it working for 1 instance with this:
[in start]
controls= new “myControlsAutoGeneratedFunction”();
…
[in update]
controls.fire.ReadValue();
As I said it works fine with only one player object the cotinous detection, the only problem is that when I join in with another player each gamepad can control both objects.
Using the new system components requires the least code. You should look at adding a PlayerInput component to your player prefab. You can then add a PlayerInputManager to your scene and give it your player prefab. It will assign gamepads to each player when they touch the controller. There’s a guide in the documentation section here (if I copied the link correctly).
You will have some sort of PlayerMotor script to do the movement and that needs a reference to the PlayerInput component.
public class MyPlayerLogic : MonoBehaviour
{
private PlayerInput m_PlayerInput;
private InputAction m_FireAction;
void Start()
{
if (m_PlayerInput == null)
{
m_PlayerInput = GetComponent<PlayerInput>();
m_PlayerInput.actions.Enable();
m_FireAction = m_PlayerInput.actions["Fire"];
}
}
void Update()
{
if (m_FireAction.triggered)
Debug.Log($"Fired {gameObject.name}");
}
}
Moments after i posted this thread I had figured it out with the “playerInput”.actions[…].ReadValue<>() called in the update function.
Thanks for the help anyways