- Home /
How to disable adding experience when level reach max
Hi, I need Some Problem solve to my issue. How can i disable adding experience when reach to level Max. So when the level is max i would not be able to add the experience So if i input some button to add an experience, it works until level max.
Answer by christian78234 · May 06, 2020 at 12:33 PM
int level = 0;
int maxLevel = 15;
int experience = 0;
if (level < maxLevel)
{
experience++;
}
@denzelkwok is right... what is level and maxLevel? What are their types? It is important to initialize your variable before you use them. Also, an easier way to add 1 to an int is to use the operator "++", for example: experience++;. It is cleaner than experience += 1.
@denzelkwok You could also use this code to update the level when experience reaches 100.
int level = 0;
int maxLevel = 15;
int experience = 0;
if (level < maxLevel)
{
experience++;
if (experience == 100)
{
experience = 0;
level++;
}
}
Answer by denzelkwok · May 07, 2020 at 08:59 AM
Thanks, but how can i set the max level? What is the code looks like? Let me know
Your answer
Follow this Question
Related Questions
New scene for minigame or not? 1 Answer
Display Audio Analysis and levels with objects 0 Answers
when i click the GUI button it doesnt load the level 1 Answer
Unity Serializer Wont Load Saves 1 Answer
Load previous scene 1 Answer