Save item/other only if you get more then previously

Hi all,

I need some help if possible… i have the code above and every time you play the game will win stars, so if you play level 1 for instance and win 2 stars this will be posted on the menu and show you that you got 2 stars for level 1. But if you play again the level 1 and you get 1 star, that will update and will show you on menu that level 1 have 1 star… is it possible to update only if the stars you get are bigger then the previous one ?

Here is the code that does the trick for the stars !

public void GameOver(int starCount)                    
        {
            if (starCount > 0)                                
            {                                                  
                levelStatusText.text = "Level " + (LevelSystemManager.Instance.CurrentLevel + 1) + " Complete";
                LevelSystemManager.Instance.LevelComplete(starCount);  
            }
            else
            {
                                                              
                levelStatusText.text = "Level " + (LevelSystemManager.Instance.CurrentLevel + 1) + " Failed";
            }
            SetStar(starCount);                              
        }






public void LevelComplete(int starAchieved)                          
        {
            levelData.levelItemArray[currentLevel].starAchieved = starAchieved;
            if (levelData.lastUnlockedLevel < (currentLevel + 1))
            {
                levelData.lastUnlockedLevel = currentLevel + 1;        
                levelData.levelItemArray[levelData.lastUnlockedLevel].unlocked = true;
            }
        }






        /// <param name="starAchieved"></param>
        private void SetStar(int starAchieved)
        {
            for (int i = 0; i < starsArray.Length; i++)         
            {

                if (i < starAchieved)
                {
                    starsArray[i].color = unlockColor;        
                }
                else
                {
                    starsArray[i].color = lockColor;            
                }
            }
        }

Yes. Why wouldn’t it be possible?

When you go to save stars, if you have a previously saved amount of stars, just compare the saved stars to the newly earned stars and only update the saved stars if the new value is larger.

Yep, thanks :slight_smile: managed to do it :slight_smile:

public void LevelComplete(int starAchieved)                            
        {
           if (starAchieved > levelData.levelItemArray[currentLevel].starAchieved)

                levelData.levelItemArray[currentLevel].starAchieved = starAchieved;  
           else if (levelData.lastUnlockedLevel < (currentLevel + 1))
            {
                levelData.lastUnlockedLevel = currentLevel + 1;          
                levelData.levelItemArray[levelData.lastUnlockedLevel].unlocked = true;
                
            }
        }