I am just playing around with the new input system and I am trying to grasp how it handles button holding.
I have set up the button like so…
How do I go about triggering different logic between when the button is held vs pressed?
As an example, a standard attack from a character, vs a charged up attack when held…
Below is what I have so far but I feel like I’m missing something with the new input system.
private ControllerMap _controlMap;
private IEnumerator ButtonHeld;
void Awake()
{
_controlMap = new ControllerMap();
_controlMap.CharacterControl.SetCallbacks(this);
}
void OnEnable()
{
_controlMap.CharacterControl.South.Enable();
}
void OnDisable()
{
_controlMap.CharacterControl.South.Disable();
}
public void OnSouth(InputAction.CallbackContext context)
{
if (context.started)
{
if (ButtonHeld != null)
{
StopCoroutine(ButtonHeld);
}
ButtonHeld = SouthHeld();
StartCoroutine(ButtonHeld);
}
if (context.canceled)
{
if (ButtonHeld != null)
{
StopCoroutine(ButtonHeld);
}
if (context.time - context.startTime < 0.3)
{
Debug.Log("X pressed logic");
}
else
{
Debug.Log("X no longer held");
}
}
}
private IEnumerator SouthHeld()
{
yield return new WaitForSeconds(0.3f);
Debug.Log("X held logic");
}