我在Unity中有一个简单的体验系统。
public void GainExperience(float experienceToAdd) // the Player gains some XP
{
currentExperience += experienceToAdd; // add the XP to the current XP
if (currentExperience > experienceNeeded) // enough XP to level up
{
currentExperience = currentExperience - experienceNeeded; // reset the current XP
experienceNeededToLevelUp *= 2; // increase the needed xp for the next level
currentLevel++; // increase the players level
skillpoints++; // gain a skillpoint
UpdateLevelText(); // GUI Update
}
UpdateXPBar(); // GUI Update
}
所以我觉得这段代码不是最好的。当我得到那么多XP,我可以升级两次或更多时,代码将不正确。
那我怎么修改呢?