Hello, I need help for the game algorithm.

When the user presses the button after passing the level, the new level is unlocked. In my code I have it Destroy the locks every time a button is pressed. But there is a problem, when the user plays the same level and wins again, other locks are unlocked without playing the 2nd level. Can you give me an idea?

public class LockDestroy : MonoBehaviour
{
    public static int newVal=1;
    public void MiniMap()
    {
        SceneManager.LoadScene(1);
        Time.timeScale = 1;
        newVal++;
        
    }

}

public class Points : MonoBehaviour
{
   public GameObject lock1;
   public GameObject lock2;
   public GameObject lock3;
   public GameObject lock4;
   private void Start()
   {
      if ( LockDestroy.newVal > 1)
      {
         Destroy(lock1);
      }

      if (LockDestroy.newVal > 2)
      {
         Destroy(lock2);
      }

      if (LockDestroy.newVal > 3)
      {
         Destroy(lock3);
      }

      if (LockDestroy.newVal >4)
      {
         Destroy(lock4);
      }
   }
}

It looks like the problem is that you’re incrementing the value of newVal in the MiniMap method every time the button is pressed, regardless of whether the user has actually passed the level. This means that if the user presses the button multiple times without passing the level, the value of newVal will be incremented multiple times and more locks will be destroyed than intended.

One way to fix this problem is to only increment the value of newVal when the user has actually passed the level. You can do this by keeping track of the user’s progress in the game and only incrementing newVal when certain conditions are met (e.g. when the user reaches a certain score, or when the user completes a level within a certain time limit). You can then use this updated value of newVal to determine which locks to destroy.

Another way to fix the problem is to keep track of which levels the user has already passed, and only destroy the locks for levels that the user has not yet passed. This way, even if the user presses the button multiple times without passing the level, the locks will not be destroyed until the user actually passes the level. You can implement this by storing the level progress in a separate variable and using that variable to determine which locks to destroy.