Question by 
               IM-A-NUB · Jan 07, 2018 at 10:00 AM · 
                scripting problemlightinglevellock  
              
 
              Level Unlock script help
With the script i have in my game manager it works and unlocks the next lvl but when i like unlock lvl4 then play lvl1 it locks lvl3 and lvl 4 so now i can only play lvl 1 and 2 can yall help?
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
 
     bool gameHasEnded = false;
 
     public float restartDealy = 1f;
 
     public GameObject completelevelUI;
 
     public string nextLevel = "Level02";
     public int LevelToUnlock = 2;
 
     public void CompleteLevel ()
     {
         completelevelUI.SetActive(true);
     }
 
     public void EndGame ()
     {
         if (gameHasEnded == false)
         {
             gameHasEnded = true;
             Debug.Log("Game Over");
             Invoke("Restart", restartDealy);
         }
 
     }
 
     void Restart ()
     {
         SceneManager.LoadScene(SceneManager.GetActiveScene().name);
     }
 
     public void WinLevel ()
     {
         Debug.Log("Level Won!");
         PlayerPrefs.SetInt("LevelReached", LevelToUnlock);
 
     }
     
 }
 
Also if u need any more of my scripts i am happy to give
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Hellium · Jan 07, 2018 at 12:05 PM
  public void WinLevel ()
  {
      int levelReached = PlayerPrefs.GetInt("LevelReached");
      Debug.Log("Level Won!");
      if( LevelToUnlock > levelReached )
          PlayerPrefs.SetInt("LevelReached", LevelToUnlock); 
  }
Your answer
 
 
             Follow this Question
Related Questions
LensFlare Doesn't Contain "brightness" Definition?!?! 0 Answers
How do I lock down a level 0 Answers
Attaching Light lerp to in-game clock 1 Answer
How to invite friends to unlock level 0 Answers
Main Menu Help 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                