I’m making a pretty simple top-down, round-based shooter that is similar in style to Dead Ops Arcade. I’m trying to implement controller support as I go so I don’t have to go back and do it later, however I’ve run into a bit of an issue.
What I’m wanting:
I want to be able to use the mouse to aim and then hold down the Left Mouse Button to shoot if the player is using a K&M. If the player is using a controller, I want the Right Control Stick to be used to both aim and shoot.
The issue:
Due to the Left Mouse Button being represented as a float value and the Right Control Stick being represented as a Vector2, I’m unable to get this working properly as I get the following error when trying to use the Right Control Stick:
InvalidOperationException: Cannot read value of type ‘float’ from control ‘/XInputControllerWindows/rightStick’ bound to action ‘Player/Attack[/Mouse/leftButton,/SwitchProControllerHID/rightStick,/XInputControllerWindows/rightStick,/SwitchProControllerHID1/rightStick]’ (control is a ‘StickControl’ with value type ‘Vector2’)
I tried creating two variables in my Input Manager. One for Gamepad Attacking and another for M&K Attacking and then reading their respective values (as shown below), however this doesn’t work. It still gives me the same error when trying to use the Right Stick. This also results in a similar error when trying to use the Left Mouse Button.
public class InputManager : MonoBehaviour
{
public static Vector2 Movement;
public static Vector2 AttackGamepad;
public static float Dodge;
public static float AttackMouse;
private PlayerInput _playerInput;
private InputAction _moveAction;
private InputAction _dodgeAction;
private InputAction _attackAction;
private void Awake()
{
_playerInput = GetComponent<PlayerInput>();
_moveAction = _playerInput.actions["Move"];
_dodgeAction = _playerInput.actions["Dodge"];
_attackAction = _playerInput.actions["Attack"];
}
private void Update()
{
Movement = _moveAction.ReadValue<Vector2>();
Dodge = _dodgeAction.ReadValue<float>();
AttackMouse = _attackAction.ReadValue<float>();
AttackGamepad = _attackAction.ReadValue<Vector2>();
}
}
I’d very much like to keep Attacking to a single Input Action rather than creating two separate ones for each Input Device. Is this possible? Any and all help is greatly appreciated!