Optimising 'Hold' Events - Is Update() the best method?

The title may be confusing, but I’ll try to explain.

I’m trying to create a ‘charge’ system, where by holding down a button you charge a bar: If charged to completion it does the action, if not it will cancel. Very simple stuff.

Now, in my newbie brain, the easiest way to do this is with an Update() function, and having Time.deltaTime, subtracted from an amount (representing the seconds the player needs to hold the button) while checking if the player is still holding the button.

But that method sucks. It’s not dynamic, it requires lots of code to be repeated in a lot of places, and it’s not as optimal as I know it could be.

Is there some way to utilise the new input system to simplify this?

Surely something as simple as ‘holding a button’ must have an elegant solution that i’m missing. If anyone can help that’ll be great!

For input actions created through the custom editor you just add a Hold interaction:

8482466--1127897--upload_2022-10-1_14-10-6.png

Here’s how to do it in code:

https://docs.unity3d.com/Packages/com.unity.inputsystem@1.4/manual/HowDoI.html#require-a-button-to-be-held-for-04-seconds-before-triggering-an-action