获取硬币并将其存储的字符中的代码....硬币可以显示在启动主文件中。
示例:
我比赛结束了,我赚了40个硬币。我再次点击播放,我收集了20个硬币。
20枚硬币是唯一会在启动时显示的硬币,之前的40枚硬币已经消失。
function OnTriggerEnter2D( other : Collider2D ) {
if (other.tag == "Coin") {
coins += 1;
PlayerPrefs.SetInt ("Coin", coins);
coinsBegin++;
Destroy(other.gameObject); PlayerPrefs.Save(); } }
function OnGUI () { GUI.Label (Rect (20, 20, 200, 40), "score: " +coins + "");
}
function GameOver(){
if(coins > PlayerPrefs.GetInt("Coin", coins)){ PlayerPrefs.SetInt("Coin", coins); } Application.LoadLevel("main"); }
答案 0 :(得分:0)
C#:
void GameOver(){
int currentCoin = PlayerPrefs.GetInt("Coin", 0);
if(currentCoin < 20){
Debug.Log("Not enough coins to play !");
}else{
currentCoin -= 20;
PlayerPrefs.SetInt ("Coin", currentCoin);
Application.LoadLevel("main");
}
}