- Home /
Dynamic Level Progress Bar
I'm trying to create a level progression bar(not the loading bar at the beginning of a scene).
I have the progress bar image set up.
I'm creating a simple runner game.
Here's my logic:
I play the level and i record the time it takes to complete the level.
i store the time in a variable: levelTime
Then I want to increase the progress bar such that it takes "levelTime" seconds to fill the whole bar(in y direction).
Here's a code that i tried.
void Update ()
{
gameObject.transform.localScale += new Vector3 (1, levelTime*Time.deltaTime, 1);
}
It just scales up too quick. Any solutions? Thank you very much
Answer by EDevJogos · Nov 19, 2017 at 03:45 PM
Whem you multiply something by time.deltaTime you're basicly fractioning that number in the frame rate so that you have that number back in 1 second, like 50 * time.deltaTime means that you'll have the value 50 each second.
What you want is to reach the value 1 in levelTime, so do time.deltaTime / levelTime.
Thanks it works. Also, is there any way so that ins$$anonymous$$d of assigning a fixed time, i can calculate the distance from the end point and then adjust the progress bar? Thank You