hello! i am a bit of a noob when it comes to unity and ive run into some trouble, ive made a level up script and at the moment pushing r adds experience to it and eventually you level up, now my problem is you start out at level 2 and not 1 and i cant figure it out.
here is the code
var curHealth : int = 100;
var maxHealth : int = 100;
var healthtext : GUIText;
var curXp : int = 0;
var maxXp : int = 0;
var xptext : GUIText;
var level : int = 0;
function Start () {
healthRegen();
}
function Update () {
healthtext.text = "Health " + curHealth + " / " + maxHealth;
xptext.text = "Level : " + level + " XP: " + curXp + " / " + maxXp;
if(curXp == maxXp)
{
levelUpSystem();
}
if(curHealth < 0 ) {
curHealth = 0;
}
if(curHealth > maxHealth) {
curHealth = maxHealth;
}
if(Input.GetKeyDown("e")) {
curHealth -= 10;
}
if(Input.GetKeyDown("r")) {
curXp += 10;
}
}
function healthRegen () {
for(i=1;i>0;i++) {
yield WaitForSeconds(0.5);
if(curHealth < maxHealth) {
curHealth++;
}
}
}
function levelUpSystem () {
curXp = 0;
maxXp = maxXp + 50;
level += 1;
maxHealth += 20;
}