Hello I would like to add a ranking system based on the player’s current level. I could use if statement for each level, but I want to keep the code optimized and small.
I tried a foreach statement but I could not get that working.
Here is the code so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerLeveler : MonoBehaviour
{
// Stats
private int level = 1;
public int ExpCurrent = 0;
public int ExpMax;
public List ranks; // Name of ranks
public List levelToNextRankList; // Level to get next rank required
public string currentRank;
public int maxLevel = 1000;
// ToNextLevel
public List expNextMax;
private void Start()
{
currentRank = ranks[level - 1];
}
private void Update()
{
if(Input.GetKeyDown(KeyCode.P))
{
LevelUp();
}
}
public void IncreaseEXP(int amount)
{
ExpCurrent += amount;
if (ExpCurrent >= ExpMax)
LevelUp();
}
void LevelUp()
{
level++;
ExpCurrent = 0;
ExpMax = expNextMax[level - 1];
// Here I would want to check if the player’s level is for example equal to 5 to change the rank from private to private first class (without an if statement so the code would not contain 40 if else statements
}
void RankUpReward(int Points, int RP)
{
Debug.Log(Points + " " + RP);
}
}