Level Button Image not hiding playerprefebs
Please Help .! Thank's I create two script given below .. I have 5 Level Button with Locker Images on Main Menu Scene ... & only 1 "Level Complete Button" in another scene ..
Now i want to unlock button 2 .. When i click 1st time on "Level Complete Button" ..Similarly go back to Main Menu select level 2 then Unlock Button 3 using the same "LevelCompleteButton"
Buttons lock & Unlock working perfect using this method .. But Locker Images are not hiding, Not working but .. So Please Check my idea for locking "Images" .. Thanks using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; using UnityEngine;
public class LevelsLocker : MonoBehaviour
{
// Start is called before the first frame update
public GameObject[] LockImages;
static int unlock;
public void Start()
{
unlock = PlayerPrefs.GetInt("Level");
}
// Update is called once per frame
void Update()
{
if (unlock >= 1)
{
LockImages [0].gameObject.SetActive(false);
}
if (unlock >= 2)
{
LockImages [1].gameObject.SetActive(false);
}
if (unlock >= 3)
{
LockImages [2].gameObject.SetActive(false);
}
if (unlock >= 4)
{
LockImages [3].gameObject.SetActive(false);
}
if (unlock >= 5)
{
LockImages [4].gameObject.SetActive(false);
}
}
public void OnLevel1()
{
unlock = 1;
PlayerPrefs.SetInt("level", unlock);
PlayerPrefs.SetInt("LevelCount", 1);
SceneManager.LoadScene("LevelComplete");
}
public void OnLevel2()
{
if (PlayerPrefs.GetInt("level") >= 2)
{
PlayerPrefs.SetInt("LevelCount", 2);
SceneManager.LoadScene("LevelComplete");
}
}
public void OnLevel3()
{
if (PlayerPrefs.GetInt("level") >= 3)
{
PlayerPrefs.SetInt("LevelCount", 3);
SceneManager.LoadScene("LevelComplete");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelButtonManager : MonoBehaviour
{
// Start is called before the first frame update
int levelnumber;
void Start()
{
levelnumber = PlayerPrefs.GetInt("LevelCount");
}
// Update is called once per frame
void Update()
{
}
public void OnNext()
{
if (PlayerPrefs.GetInt("level") == PlayerPrefs.GetInt("LevelCount"))
{
PlayerPrefs.SetInt("level", PlayerPrefs.GetInt("level") + 1);
PlayerPrefs.SetInt("LevelCount", PlayerPrefs.GetInt("LevelCount") + 1);
SceneManager.LoadScene("TestMenu");
}
}
}
Your answer
Follow this Question
Related Questions
SetActive dosen't work 0 Answers
How can i get the value of the Scrpit what is attached on the Image 0 Answers
How can I save values in an array using PlayerPrefs? 0 Answers
LevelSelect Reset Button 0 Answers
Level Unlock System....frustrated,Building a level unlock system using player prefs 0 Answers