Now, I have some code that I’m trying to write, and I can get the script to print the messages (so I can debug) and everything looks right in the inspector.
My issue, however, is that when I click to test the levelUp function each level seems to think that the XP required for a level up is the same as the amount of XP needed for a level 1 character. Here’s the code so you more knowledgeable minds out there can tell me what I’m not doing correctly and how best to correct any mistakes I’ve made:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelUp : MonoBehaviour {
public int currentLevel;
public int currentXP;
public int nextLevel;
public int nextLevelXP;
void Start() {
currentLevel = 1;
nextLevel = currentLevel++;
nextLevelXP = currentLevel * nextLevel * 500;
}
void Update() {
AddXP();
if (currentXP < nextLevelXP) {
print("You need " + (nextLevelXP - currentXP) + " to level up.");
}
}
void AddXP() {
if (Input.GetButtonUp("Fire1")) {
currentXP += nextLevelXP;
}
if (currentXP >= nextLevelXP) {
levelUp();
}
}
void levelUp() {
currentLevel++;
}
}