I want to make a ‘previous’ and a ‘next’ action, two different discrete actions. I have two different control types, one where this is two different physical buttons, and one where I want it to be left and right push on a joystick.
It seems to me that this is not possible? Is it even possible to convert an analog into a button to begin with? I know shoulder triggers on gamepads have a “button version” of itself. But it seems like you cannot interpret a stick into multiple discrete button actions.
Of course this is trivial to do in code, but with this gigantic super abstracted Input system the we find ourselves encouraged to use, I think it should really be possible.
You can do it the other way around! With 1D Axis, you can convert two physical buttons into an axis:
Using the ‘cycle’ example in my screenshot, you could use it from code in two ways:
void Awake()
{
m_Controls = new SimpleControls();
m_Controls.gameplay.cycle.performed +=
ctx =>
{
var cycle = ctx.ReadValue<float>();
if (Mathf.Abs(cycle) >= 1f)
{
// I think performed is fired each time the value increases, so
// we only want to respond at the maximum.
Debug.Log($"From event handler: {cycle}", this);
}
};
}
void Update()
{
var cycle = m_Controls.gameplay.cycle.ReadValue<float>();
if (Mathf.Abs(cycle) >= 1f)
{
// TODO: ignore this input until it's released.
Debug.Log($"From Update: {cycle}", this);
}
}
(Additional refinement required, but you get the idea.)