My question is almost completely what the title says. I am wondering how I would limit the length of my xp bar to a certain amount. The best example of what I want to do would be Mincraft’s xp bar. Any ideas?
You can “normalize” your XP and multiply it by a value, this puts it in a range between 0 and 1. something like this:
var xp : float;
var maxXp : float;
var xpBarFullRect : Rect;
function OnGUI() {
var normalizedXp = xp / maxXp;
var xpBarRect = xpBarFullRect;
xpBarRect.width *= normalizedXp;
GUI.Box(xpBarRect, xp + "/" + maxXp);
}
Please keep in mind that I never code in javascript + I coded this in a browser… so I can almost guarentee my code won’t work… but if u can read you should be able to translate my code into javascript (if you had of asked for C# ide been able to write 100% bug free code :P) and also, I havn’t tested this, this function is based purely on theory…
say we have a xp scale from 0 → 100 and curr xp == 54
get currValue and take min value from it
54 - 0 = 54
get the max value and take the min value from it
100 - 0 = 100
then we divide the new curr value by the new max value
54/100
which gives us 0.54
Then what you do is define the screenspace for the box
a--------------------b
c--------------------d
then when you draw the box you would give it this: