Creating a Charging bar UI With New Input System.

Joseph Hibbs
2 min readAug 19, 2023

--

First we create an Input action map for UI, and a ChargeBar Action, which i set the key to space bar. Then generate the C# class script.

Now from there we create the Input Script. We will need our Input action and our Slider so we will be using systems UnityEngine.UI;

Now we initialize the UI input and enable the UI Input map. We will be using a simple Started and Canceled method with a Coroutine.

When we start the Input we set our bool _isCharging to True and also start our coroutine. On Canceled we set our bool _isCharging to False.

Now within our coroutine while is charging is true we add to the slider value by multiplying it by 1 and time.deltaTime. But say I want it to take 5 seconds to fully charge Ican then divide that number by 5. Now when I release the Charge Input the while loop is no longer true so it continues, which then checks to see if the value is greater than 0 if it is then decrement it by 1 and deltaTime which i divided by 10 to make it take 10 seconds to charge. With all that finished we now have a basic charging UI system.

--

--