Unity 5保存和加载变量

时间:2016-10-11 13:43:25

标签: save load unity5

我知道我可以使用PlayerPrefs保存int,float,string,但是我怎样才能保存一个布尔值,就像玩家有钱一样,并且他买了一个升级版,如果玩家购买了升级并加载了怎么能保存它下一次?

我有这样的升级:

  public void Computer()
{
    if(tier1 == true && Click.money >= cost)
    {
        Click.money -= cost;
        ItemNameInfo.text = "[TIER II]Computer";
        UpgradeInfo.text = "Wooaah! Upgrade Time!\n(Gives +5 CPS)";
        cost = 1000;
        costInfo.text = "Cost: " + cost;
        Click.moneyperclick += 1;
        tier1 = false;
        tier2 = true;
    }
    else if(tier2 == true && Click.money >= cost)
    {
        Click.money -= cost;
        ItemNameInfo.text = "[TIER III]Computer";
        UpgradeInfo.text = "It's still isn't good enough\n(Gives +10 CPS)";
        cost = 20000;
        costInfo.text = "Cost: " + cost;
        Click.moneyperclick += 5;
        tier2 = false;
        tier3 = true;
    }

}

1 个答案:

答案 0 :(得分:0)

您无法将bool保存到Player Prefs。

我倾向于使用int。

例如,假设我们有一个项目“item1”。

检查玩家是否已解锁该项目:

if(PlayerPrefs.GetInt("hasItem1",0) == 1){
    //player has item 1
}

解锁item1:

PlayerPrefs.SetInt("hasItem1",1);