Add to number little by little so it ends at specific number.

Hey guys,

Sorry about the weird title, but I can’t think of any concise way to ask this.

I’m trying to make a timebar (similar to this), but I can’t figure out how to position the place marker every frame. I know I’ll have to use audio.time to get the place in the song, but I don’t know how to convert that into the length of the timebar (which is a variable length).

Incase this isn’t clear, let’s say the timebar is 800px wide, audio.time is currently 243.8 and the clip.length is 571.6. The place marker isn’t going to be correctly positioned if I just use the audio.time value, so how would I make sure it’ll end at 800px when the song reaches 571.6?

If you can think of a better way for me to explain this, please let me know.

Thanks for taking the time to read this!
-Gibson

Have a look here

You can try something like :

float x = audio.time;
float currLength = x * 800 / clip.length;

Use this code in the Update method. Then you can update the slider (or whatever gui object you use) accordingly to currLength value