Ok guys I spent the last few days developing my android project.
I am trying to add a cooldown bar to a UI Button , basically when you press the button the bar will appear and it will be fully filled after the time in the script passed (during that time the button it’s non interactible).
That’s an example :
function Cooldown()
{
yield WaitForSeconds (5);
Money(); //calling a function that adds the money after the cooldown it's done
XP(); //same
Cooldownbar(); //how do I make it?
}
Instead of waiting 5 seconds and doing everything, do something like this:
function Cooldown()
{
var elapsedTime : float = 0f;
//Set the bar "fill" to 0 here
while (elapsedTime < 5f)
{
//Update the bar here
elapsedTime += Time.deltaTime;
yield;
}
Money();
XP();
}
Graphically, the bar can be made in a lot of ways, you can have a single rectangle image, and change the width to show how much is filled. In the “//update the bar here” code you use send the percentage of time that has passed with: elapsedTime/5f