Hi,
I’m trying to do a progress bar of the level, but it depends on time, and not on location (i.e. the level lasts X seconds). I’ve searched around for an answer but came out empty. (almost everything else is location related)
the visual is via 2 cubes, as one is the progression and the other is total length and the first is the child of the latter. as a result it needs to move from -0.5 to 0.5 in X seconds.
I tried to calculate this, but I’m missing a key factor (multiplier) that I can’t figure out
…
The key factor isn’t fixed, because when i tried various times, it changed…
I tried this: [C#]
public GameObject progBar; //the child progress bar
public int LevelTime = 10;
Vector3 progVector; // a temp var for vector changes
float deltaSegment;
float timer;
void Start ()
{
timer = 0;
deltaSegment = LevelTime / Time.deltaTime; //to figure how much it needs to move each frame
}
void FixedUpdate()
{
gameProgress();
}
void gameProgress()
{
timer += Time.deltaTime;
progVector = progBar.transform.position;
progVector.y += (1/deltaSegment) * ???; // THE SILVER LINE
progBar.transform.position = progVector;
if(progBar.transform.localPosition.y >= 0.5f)
Debug.Log ("Reached the end (" + progBar.transform.localPosition.y + ") at " + timer + " Seconds"); //debugging how long it takes it to reach the end
if(timer >= LevelTime)
Debug.Log ("Level finished");
}
I’ve tried calling through Update and FixedUpdate, but no change there. and if I try through GUI, I think I’ll have the same problem…
any suggestions, please?