Sunday, 9 October 2016

Level Lock & Unlock Script

public Button[] buttonLevel;
public Text[] textLevel;
public GameObject[] LoadObj;
AsyncOperation async;
string levelNameBG;

public GameObject loadingBar;

int mylock;
public int minLock;

// Use this for initialization
void Awake () {
//PlayerPrefs.DeleteAll ();

//level
if (Application.loadedLevelName == "LevelSelect") {
PlayerPrefs.SetInt ("myWorld", 0);
} else if (Application.loadedLevelName == "LevelSelect_2") {
PlayerPrefs.SetInt ("myWorld", 1);
}else if (Application.loadedLevelName == "LevelSelect_3") {
PlayerPrefs.SetInt ("myWorld", 2);
}
//PlayerPrefs.DeleteAll();
if (LoadObj.Length != 0) {
LoadObj [0].SetActive (false);
LoadObj [1].SetActive (false);
LoadObj [2].SetActive (false);
}

for (int i=0; i<textLevel.Length; i++) {
textLevel[i].text = (i+1+minLock).ToString();

}


if (Application.loadedLevelName == "LevelSelect") {
mylock = PlayerPrefs.GetInt("levellock") ;//PlayerPrefs.GetInt ("LevelLock")-minLock;
} else if (Application.loadedLevelName == "LevelSelect_2") {
mylock = PlayerPrefs.GetInt("levellock2") ;//PlayerPrefs.GetInt ("LevelLock")-minLock;
}else if (Application.loadedLevelName == "LevelSelect_3") {
mylock = PlayerPrefs.GetInt("levellock3") ;//PlayerPrefs.GetInt ("LevelLock")-minLock;
}

if (mylock == 0) {
mylock = 1;
}
//if (mylock < 9) {
for (int i=0; i<mylock; i++) {
buttonLevel [i].interactable = true;

/* }
} else {
for (int i=0; i<9; i++) {
buttonLevel [i].interactable = true;
}*/
}


}

void Start(){
GoogleManager.sendScreen = true;
}

void Update()
{
}
public void levelName(string levelName){

// GameObject cam= GameObject.Find("Main Camera").GetComponent<"cameraShake">() as cameraShake;
// cam.Shake();

levelNameBG = levelName;
if (LoadObj.Length != 0) {
LoadObj [0].SetActive (true);
LoadObj [1].SetActive (true);
LoadObj [2].SetActive (true);
}
StartCoroutine(load(levelNameBG));


}

public void BackToHomeScene()
{

Application.LoadLevel("LevelChoose");



}



IEnumerator load(string levelName) {

async = Application.LoadLevelAsync(levelName);
while (!async.isDone)
{
//loadingBar.value = async.progress;
loadingBar.SetActive(true);
yield return null;
}
}

No comments:

Post a Comment