如何使用GUI按钮和PlayerPrefs制作Level Unlocker?

时间:2014-03-02 06:08:00

标签: unity3d unityscript

#pragma strict

var challenge1 : Texture;
var challenge2 : Texture;
var challenge3 : Texture;
var LevelOneEnabled = true;
var LevelTwoEnabled = false;
var LevelThreeEnabled = false;
var Score : TextMesh;
var Score2 : TextMesh;
var Score3 : TextMesh;
function Start(){

}
function Awake(){
Score.text = "Highscore: "+ PlayerPrefs.GetInt("JeepneyScore");
Score2.text = "Highscore: "+ PlayerPrefs.GetInt("JeepneyScore2");
Score3.text = "Best Time: "+ PlayerPrefs.GetFloat("JeepneyScore3");
}
function OnGUI()
{


GUI.enabled = LevelOneEnabled;
if(GUI.Button(Rect(400,100,250,250),challenge1)){
Application.LoadLevel("LoadScene");
}
GUI.enabled = LevelTwoEnabled;
if(GUI.Button(Rect(700,100,250,250),challenge2)){
Application.LoadLevel("LoadScene2");
}
GUI.enabled = LevelThreeEnabled;
if(GUI.Button(Rect(1000,100,250,250),challenge3)){
Application.LoadLevel("LoadScene3");
}

}
  • 任何人都知道在playerprefs中获取逻辑以便LoadScene2和3 完成第一次任务后会解锁吗? 我希望得到答案:(

1 个答案:

答案 0 :(得分:0)

放入

var level : int;

然后开始

level = PlayerPrefs.GetInt("level",0);

然后在你的if(GUI.Buttons){}

if(level >= 2){}

if(level >= 3){}

依此类推,在你的实际级别中,一旦他们完成了这个级别就在你的playerprefs中设置了int,可能再次加载int并使用if来检查它是否大于然后替换,如果它不是

编辑:

var levelnum : int = 2;
PlayerPrefs.SetInt("level",levelnum);