Help with Exp Bar

Hi, im working on an Experience bar and i need some help to make the bar grow with my currentExp and have a max distance… here is the code:

var curExp = 0;
var curLevel = 0;
var ExpToLevel = 99;

var ExpBarLength = 0;
var ExpBarMaxLength = 90;
var ExpBarLength2 = 1;

ExpBarLength = curExp * ExpBarLength2;
function OnGUI () {
	(GUI.Box(Rect(30,600,ExpBarLength,20), curExp + "exp"));
	(GUI.Box(Rect(50, 100, 50, 25), "lvl " + curLevel));
	
	if (ExpBarLength > ExpBarMaxLength) {
		ExpBarLength = ExpBarMaxLength;
	}
	
	
	if (curExp > ExpToLevel) {
		curExp = 0;
		curLevel = curLevel + 1;
		ExpToLevel = ExpToLevel + 50;
		print("Level Up!");
	}

}

Can you help me with this? By the way the code is not fully completed just need help with that…

what more do u want to do in this? I think it works

Use GUI.DrawTexture() instead of a box.

var expTexture : Texture;
var curExp : float;
function OnGUI()
{
    GUI.DrawTexture(Rect(10, 10, 60, curExp), expTexture);
}

// So when you modify curExp your size of texture will also change

// This is for demo purpose to show it is working
function Update()
{
    curExp++;
}

The script works but not fully… Couse the bar can go past the whole screen. Ill test zine92’s code
THX…

If you need to maintain the length of the bar I think you should replace this part of code

(GUI.Box(Rect(30,600,ExpBarLength,20), curExp + "exp"));

change ExpBarLength with your variables which describes this

max exp bar length * current experience / max experience

Personally i think your if loops should be working. The one that checks if experience is more than certain amount. My script do not have experience checking.

Well, i realized there’s a typo in my previous script and as a apology, i made a new one. I packaged it and you just import the package and put the prefab on stage to try it out. Make sure maxExp is not 0.

627654–22395–$experience.unitypackage (3.5 KB)

If you need some more help on stuff like that Burgzergarcade have some very good tuts for RPG based stuff etc.

BurgzergArcade has some great tutorials.

Here is a link: burgzergarcade.com

mm, I like his tutorials… But i dont like C#. I dont know why but i just like writing in javascript more. Is it a MUST to learn C# too?

I would say that, to migrate to C# would be the best thing you can do. Because, although there is nothing wrong with JavaScript, it’s a LOT more simpler, in C#, to debug, as you have a lot more options open to you. And finding silly things like mis-typed variables etc won’t be an issue in C#, because it will complain about it :slight_smile:

In Unity, C#* JavaScript are very similar cause the library are the same. Matte005 ? have you resolved your issue ?

Nope. Not a must to learn c# if you are just learning the basics of Unity. I had no problem with js too. Just started learning C# and having no problem. I think doing things in js is more faster (the more prototypical way) and in c# is more neat. Both works around the same.

Thx! I worked with some of my issues but i still got some in acces variables from other scripts.

we are here, post it if you’ve problems.

Look at my other thread couse i posted more there so you can see my problem.

name: Help with enemy GUI/hp

Help me please all man on exp bar