Question by
SepehrM · Jul 09, 2017 at 08:33 PM ·
locklevel editorlevel select
Problem With Lock the Levels
hi...i made code for my level select screen for when i completed level 1 the lock image on the level 2 will disappear...im starting to playing level 2 and compelete that either...it will unlock the level 3 for me but lock the level 2 again after i finish that...and it happens for the next levels aswell...where is the problem?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LevelMenu : MonoBehaviour {
public Button btn1, btn2, btn3;
public GameObject Lock1, Lock2, Lock3;
// Use this for initialization
void Start () {
PlayerPrefs.SetString ("lo1", "On");
if (PlayerPrefs.GetString ("lo1") == "On")
Lock1.SetActive (false);
if (PlayerPrefs.GetString ("lo2") == "On")
Lock2.SetActive (false);
if (PlayerPrefs.GetString ("lo3") == "On")
Lock3.SetActive (false);
btn1.onClick.AddListener (()=>{
if(PlayerPrefs.GetString ("lo1") == "On")
Application.LoadLevel ("lo1");
});
btn2.onClick.AddListener (()=>{
if(PlayerPrefs.GetString ("lo2") == "On")
Application.LoadLevel ("lo2");
});
btn3.onClick.AddListener (()=>{
if(PlayerPrefs.GetString ("lo3") == "On")
Application.LoadLevel ("lo3");
});
}
// Update is called once per frame
void Update () {
}
}
i also added this code to my HUD script where it tells you win the game:
public void OnGameWin(int score)
{
gameOver.ShowWin (score, starIdx);
if (starIdx > PlayerPrefs.GetInt (UnityEngine.SceneManagement.SceneManager.GetActiveScene ().name, 0)) {
PlayerPrefs.SetInt (UnityEngine.SceneManagement.SceneManager.GetActiveScene ().name, starIdx);
PlayerPrefs.SetString (NextLevel, "On");
Comment