Unlocked levels Lock if a previous level played
I have been having an issue with my level locking system where it will lock levels that have already been unlocked after playing previous levels. There is surprisingly little information on this but the things that I have found suggest that you need to check to see if there is a key any only save it then but I have had no success with this so far. My code is below if anyone could see what I am doing wrong or has a good way of doing this it would be much appreciated as I have been working on this for over a week now.
{ public GameObject CompletedLevel; int sceneIndex, levelPassed;
 // Use this for initialization
 void Start () {
     
     sceneIndex = SceneManager.GetActiveScene ().buildIndex;//Gets active scene
     levelPassed = PlayerPrefs.GetInt ("LevelPassed");//Gets PlayerPrefs for levelPassed
 }
 // Update is called once per frame
 public void Update()
 {
      var boxes = GameObject.FindGameObjectsWithTag("grass");
     if (boxes.Length == 0)
     {
     
     
         
         if(!PlayerPrefs.HasKey("LevelPassed") || PlayerPrefs.GetInt("LevelPassed") == 1)
         {
         
         CompletedLevel.SetActive (true);
         
         PlayerPrefs.SetInt("LevelPassed", 1);
         
         PlayerPrefs.Save();
         
         
         Debug.Log("Not Saved");
         
         
     }
     else
     {
         CompletedLevel.SetActive (true);
         PlayerPrefs.SetInt ("LevelPassed", sceneIndex);
         Debug.Log("Saved WooHoo!!!!");
     
     
     }
     
     
      GameObject[] argo = GameObject.FindGameObjectsWithTag("cloudpf");
         for (int i = 0; i < argo.Length; i++)
         argo[i].SetActive(false);
     
     Destroy (GameObject.FindWithTag("timer"));
     
     } 
         
 }
 
               }
Your answer
 
             Follow this Question
Related Questions
How to invite friends to unlock level 0 Answers
Bug with Lock Unlock System 0 Answers
unlock levels (or items ) without PlayerPrefs 0 Answers
Level Unlock System....frustrated,Building a level unlock system using player prefs 0 Answers
Player Prefs Issue 0 Answers