- Home /
How can I collect playerprefs values?
I have variable stars name, How can i add all the values of the stars variable to each other and to collect them in another variable.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LevelSelectScript : MonoBehaviour {
private int worldIndex;
private int levelIndex;
private int stars = 0;
private int starvedro;
void Start (){
//loop thorugh all the worlds
for(int i = 1; i <= LockLevel.worlds; i++){
if(Application.loadedLevelName == "World"+i){
worldIndex = i; //save the world index value
CheckLockedLevels(); //check for the locked levels
}
}
}
//Level to load on button click. Will be used for Level button click event
public void Selectlevel(string worldLevel){
Application.LoadLevel("Level" + worldLevel); //load the level
}
//function to check for the levels locked
void CheckLockedLevels (){
//loop through the levels of a particular world
for(int j = 1; j < LockLevel.levels; j++){
//get the number of stars obtained for that particular level
//used to enable the image which should be displayed in the World1 scene beside the individual levels
stars = PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +j.ToString()+"stars");
levelIndex = (j+1);
//enable the respective image based on the stars variable value
GameObject.Find(j+"star"+stars).GetComponent<Image>().enabled = true;
//check if the level is locked
if((PlayerPrefs.GetInt("level"+worldIndex.ToString() +":" +levelIndex.ToString()))==1){
//disable the lock object which hides the level button
GameObject.Find("LockedLevel"+levelIndex).SetActive(false);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
KeyCode to Ui ? for mobile 1 Answer
Options save 1 Answer