- Home /
can figure out why it starts at level 2
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;
}
Answer by ByteSheep · Mar 09, 2013 at 06:12 PM
You simply have to make maxXp greater than null at the start. Since if it is set to zero you will level up right away.. Try setting maxXp to 50. Let me know if this works or if you have already set it higher than 0 in the inspector!
YAY! yeah that worked perfectly, was actually quite a stupid question now i think about it. thank you!
No problem, If you like you can mark this answer as accepted so your question doesn't appear as unanswered anymore ;)
Your answer
Follow this Question
Related Questions
In Game Play, FPC automatically falls through terrain! 1 Answer
Game crashes or does not load levels when told to? 2 Answers
Why is the game scene empty when I press "play"? 1 Answer
level up need help 1 Answer
how do you actually stop a game? 3 Answers