- Home /
Leveling system
I'm looking for a tutorial on creating a leveling system with a level progress bar like you would find in World of warcraft. I want it so the bar fills as you gain exp and when you level the bar emptys and fills all over again for the next level reqireing the new exp. Is there any tutorial or anything any one know of for this. I created one but I cant get the exp bar to to fill fill up then change for the next level. I am only look like 10 level to start with.
Thats a broad question. Perhaps it would help others provide an answer if you can describe where you have difficulties.
Well here is a basic example of a progress bar with an exp amount, a maxExp amount. This test lets you add exp by pressing the '+' on the keypad. In this example, I have exp starting at zero, maxExp set to 1000, and a Texture that fills in the background (gui box) as you progress. No matter what you set your maxExp to, it will never overfill the background box, since the simple formula here keeps the fill based on the percentage of the width of the box. I've attached an example of what kind of texture you could use, just a 32x32 green fill. Assign this texture in the inspector. The higher you set your maxExp, the slower this will fill.
using UnityEngine;
using System.Collections;
public class Example : $$anonymous$$onoBehaviour
{
public Texture2D bar;
Rect bgRect;
Rect barRect;
Rect labelRect;
int exp = 0;
public int maxExp = 1000;
void Awake()
{
bgRect = new Rect(32, 32, 512, 24);
barRect = new Rect(34, 34, 0, 20);
labelRect = new Rect(32, 64, 128, 24);
}
void Update()
{
if(exp > 0)
barRect.width = exp * bgRect.width / maxExp;
//TEST
if(exp < maxExp)
{
if(Input.Get$$anonymous$$ey ($$anonymous$$eyCode.$$anonymous$$eypadPlus))
exp += 10;
}
}
void OnGUI()
{
GUI.Box (bgRect, GUIContent.none);
GUI.DrawTexture(barRect, bar);
GUI.Label(labelRect, exp.ToString());
}
}
Answer by Yokimato · Aug 14, 2013 at 04:23 PM
Creating a progress bar that fills is extremely easy with NGui. They have a free version, I suggest taking a look there.