Creating A Progress Bar w/ New Unity Input system

Richard Morgan
2 min readSep 28, 2022

--

Let’s use the New Unity Input System to create a slider that “charges up” when the space bar is held, and “discharges” when the space bar is released:

First, we’ll add a Canvas, and add a Slider:

And add a Slider Input script:

Now we’ll create an Input Actions for our slider:

To the ProgressBar Action Map, we’ll need a Charge Action of type Button. Then we’ll set the space as the Charge Binding. Here are the settings for our SliderInputActions:

Now let’s update our Slider Input script to:
1) Get a reference to the input actions
2) Enable the input action map
3) Register the perform functions

Now we need our functions, Charging_started, and Charging_canceled:

And a coroutine to move the slider:

And that’s it. Now our slider will take 3 seconds to go from 0 to 100% and 5 seconds to go from 100 to 0%.

--

--