Question by
simone9725 · Mar 19, 2016 at 01:36 PM ·
playerprefsscore system
Unlock a level if score in the previous level is right
Well I have created a system that stores all the score but I would that net level is avaible olny if I reached the desired score in the previous one
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class GestioneLivelli : MonoBehaviour {
private int score;
public int PuntiNecessari;
public int CurrentLevel;
public Button Livello1;
public Button Livello2;
public Button Livello3;
public Button Livello4;
public Button Livello5;
public Button Livello6;
public Button Livello7;
public Button Livello8;
public Button Livello9;
public Button Livello10;
public Button Livello11;
public Button Livello12;
bool Lev1 = false;
bool Lev2=false;
bool Lev3=false;
bool Lev4=false;
bool Lev5 = false;
bool Lev6=false;
bool Lev7=false;
bool Lev8=false;
bool Lev9 = false;
bool Lev10=false;
bool Lev11=false;
bool Lev12=false;
bool completo1;
bool completo2;
bool completo3;
bool completo4;
bool completo5;
bool completo6;
bool completo7;
bool completo8;
bool completo9;
bool completo10;
bool completo11;
bool completo12;
public BossLaury Laura;
public BossSara Sara;
public BossZimZim Zimmy;
// Use this for initialization
void Start () {
score = PlayerPrefs.GetInt("bestScore");
Lev1 = PlayerPrefs.GetInt("Lev1", 0) == 1;
Lev2 = PlayerPrefs.GetInt("Lev2", 0) == 1;
Lev3 = PlayerPrefs.GetInt("Lev3", 0) == 1;
Lev4 = PlayerPrefs.GetInt("Lev4", 0) == 1;
Lev5 = PlayerPrefs.GetInt("Lev5", 0) == 1;
Lev6 = PlayerPrefs.GetInt("Lev6", 0) == 1;
Lev7 = PlayerPrefs.GetInt("Lev7", 0) == 1;
Lev8 = PlayerPrefs.GetInt("Lev8", 0) == 1;
Lev9 = PlayerPrefs.GetInt("Lev9", 0) == 1;
Lev10 = PlayerPrefs.GetInt("Lev10", 0) == 1;
Lev11= PlayerPrefs.GetInt("Lev11", 0) == 1;
Lev12 = PlayerPrefs.GetInt("Lev12", 0) == 1;
bool completo1=false;
bool completo2=false;
bool completo3=false;
bool completo4=false;
bool completo5=false;
bool completo6=false;
bool completo7=false;
bool completo8=false;
bool completo9=false;
bool completo10=false;
bool completo11=false;
bool completo12=false;
}
void Update ()
{
CheckLevels ();
}
// Update is called once per frame
void CheckLevels () {
// Have we enough cash to buy them?
if (score >= 20000)
{
Livello1.enabled = true;
Livello1.GetComponent<Image>().color = Color.white;
Lev1=true;
}else{
Livello1.enabled=false;
Livello1.GetComponent<Image>().color = Color.black;
completo1 = false;
}
if (score >= 30000&&completo1==true)
{
Livello2.enabled = true;
Livello2.GetComponent<Image>().color = Color.white;
Lev2=true;
}else{
Livello2.enabled=false;
Livello2.GetComponent<Image>().color = Color.black;
completo2=false;
}
if (score >= 40000&&completo2)
{
Livello3.enabled = true;
Livello3.GetComponent<Image>().color = Color.white;
Lev3=true;
}else{
Livello3.enabled=false;
Livello3.GetComponent<Image>().color = Color.black;
}
if (score >=50000&&completo3==true)
{
Livello4.enabled = true;
Livello4.GetComponent<Image>().color = Color.white;
Lev4=true;
}
else{
Livello4.enabled=false;
Livello4.GetComponent<Image>().color = Color.black;
}
if (score >= 60000)
{
Livello5.enabled = true;
Livello5.GetComponent<Image>().color = Color.white;
Lev5=true;
}
else{
Livello5.enabled=false;
Livello5.GetComponent<Image>().color = Color.black;
}
if (score >= 65000)
{
Livello6.enabled = true;
Livello6.GetComponent<Image>().color = Color.white;
Lev6=true;
}
else{
Livello6.enabled=false;
Livello6.GetComponent<Image>().color = Color.black;
}
if (score >= 70000)
{
Livello7.enabled = true;
Livello7.GetComponent<Image>().color = Color.white;
Lev7=true;
//boss
}
else{
Livello7.enabled=false;
Livello7.GetComponent<Image>().color = Color.black;
}
if (score >= 75000)
{
Livello8.enabled = true;
Livello8.GetComponent<Image>().color = Color.white;
Lev8=true;
}
else{
Livello8.enabled=false;
Livello8.GetComponent<Image>().color = Color.black;
}
if (score >= 76000)
{
Livello9.enabled = true;
Livello9.GetComponent<Image>().color = Color.white;
Lev9=true;
}
else{
Livello9.enabled=false;
Livello9.GetComponent<Image>().color = Color.black;
}
if (score >= 77000)
{
Livello10.enabled = true;
Livello10.GetComponent<Image>().color = Color.white;
Lev10=true;
}
else{
Livello10.enabled=false;
Livello10.GetComponent<Image>().color = Color.black;
}
if (score >= 80000)
{
Livello11.enabled = true;
Livello11.GetComponent<Image>().color = Color.white;
Lev11=true;
//boss
}
else{
Livello11.enabled=false;
Livello11.GetComponent<Image>().color = Color.black;
}
if (score >= 90000)
{
Livello12.enabled = true;
Livello12.GetComponent<Image>().color = Color.white;
Lev11=true;
}
else{
Livello12.enabled=false;
Livello12.GetComponent<Image>().color = Color.black;
}
}
void OnDestroy()
{
PlayerPrefs.SetInt ("Lev1", Lev1 ? 1 : 0);
PlayerPrefs.SetInt ("Lev2", Lev2 ? 1 : 0);
PlayerPrefs.SetInt ("Lev3", Lev3 ? 1 : 0);
PlayerPrefs.SetInt ("Lev4", Lev4 ? 1 : 0);
PlayerPrefs.SetInt ("Lev5", Lev5 ? 1 : 0);
PlayerPrefs.SetInt ("Lev6", Lev6 ? 1 : 0);
PlayerPrefs.SetInt ("Lev7", Lev7 ? 1 : 0);
PlayerPrefs.SetInt ("Lev8", Lev8 ? 1 : 0);
PlayerPrefs.SetInt ("Lev9", Lev9 ? 1 : 0);
PlayerPrefs.SetInt ("Lev10", Lev10 ? 1 : 0);
PlayerPrefs.SetInt ("Lev11", Lev11 ? 1 : 0);
PlayerPrefs.SetInt ("Lev12", Lev12 ? 1 : 0);
PlayerPrefs.Save();
}
}
Pls I don't want destroy hours of work could someone help on this
Ps:If there is a problem and it isn't approved could you say where is my mistake)
Comment