Unity 5 PlayerPrefs加载0值

时间:2017-12-07 11:14:51

标签: c# unity3d unity5 saving-data

我正在创建一个简单的PlayerPrefs脚本,它应该加载我的统计数据并保存它们每一帧我将它附加在每个场景中的“DontDestroyOnLoad”对象但由于某种原因启动游戏所有统计数据在这里变为0代码说我在每10秒钟保存一次统计信息,因为我在解决方案中读取PlayerPrefs.save应该修复它但它没有

void Start () {
    InvokeRepeating ("SaveGame",0,10f);
    Stats.totalcoins = PlayerPrefs.GetInt ("totalcoins");
    Stats.personalbest = PlayerPrefs.GetInt ("PersonalBest");
    Stats.CarrotSpawnRateLVL = PlayerPrefs.GetInt ("CarrotSpawnRateLvL");
    Stats.CarrotSpawnRate = PlayerPrefs.GetFloat ("CarrotSpawnRate");
    Stats.CarrotSpawnRateUpgradeCost = PlayerPrefs.GetInt ("CarrotSpawnRateUpgradeCost");
    Stats.CarrotEffectLVL = PlayerPrefs.GetInt ("CarrotEffectLvL");
    Stats.CarrotEffect = PlayerPrefs.GetFloat ("CarrotEffect");
    Stats.CarrotEffectUpgradeCost = PlayerPrefs.GetInt ("CarrotEffectUpgradeCost");
    Stats.UmbrellaDurabilityLVL = PlayerPrefs.GetInt ("UmbrellaDurabilityLvL");
    Stats.UmbrellaDurability = PlayerPrefs.GetFloat ("UmbrellaDurability");
    Stats.UmbrellaDurabilityUpgradeCost = PlayerPrefs.GetInt ("UmbrellaDurabilityUpgradeCost");
    Stats.UmbrellaSizeLVL = PlayerPrefs.GetInt ("UmbrellaSizeLvL");
    Stats.UmbrellaSize = PlayerPrefs.GetFloat ("UmbrellaSize");
    Stats.UmbrellaSizeUpgradeCost = PlayerPrefs.GetInt ("UmbrellaSizeUpgadeCost");
    Stats.Tree1Bought = PlayerPrefs.GetInt ("Tree1Bought");
    Stats.Tree1SizeLVL = PlayerPrefs.GetInt ("Tree1LvL");
    Stats.Tree1Size = PlayerPrefs.GetFloat ("Tree1Size");
    Stats.Tree1SizeUpgradeCost = PlayerPrefs.GetInt ("Tree1UpgradeCost");
    Stats.Tree2Bought = PlayerPrefs.GetInt ("Tree2Bought");
    Stats.Tree2SizeLVL = PlayerPrefs.GetInt ("Tree2LvL");
    Stats.Tree2Size = PlayerPrefs.GetFloat ("Tree2Size");
    Stats.Tree2SizeUpgradeCost = PlayerPrefs.GetInt ("Tree2UpgradeCost");
    Stats.Tree3Bought = PlayerPrefs.GetInt ("Tree3Bought");
    Stats.Tree3SizeLVL = PlayerPrefs.GetInt ("Tree3LvL");
    Stats.Tree3Size = PlayerPrefs.GetFloat ("Tree3Size");
    Stats.Tree3SizeUpgradeCost = PlayerPrefs.GetInt ("Tree3UpgradeCost");
    Stats.BuyTreesCost = PlayerPrefs.GetInt ("BuyTreeCost");

}

// Update is called once per frame
void Update () {
    Debug.Log (Stats.totalcoins);
    PlayerPrefs.SetInt ("totalcoins", Stats.totalcoins);
    PlayerPrefs.SetInt ("PersonalBest", Stats.personalbest);
    PlayerPrefs.SetInt ("CarrotSpawnRateLvL", Stats.CarrotSpawnRateLVL);
    PlayerPrefs.SetFloat ("CarrotSpawnRate", Stats.CarrotSpawnRate);
    PlayerPrefs.SetInt ("CarrotSpawnRateUpgradeCost", Stats.CarrotSpawnRateUpgradeCost);
    PlayerPrefs.SetInt ("CarrotEffectLvL", Stats.CarrotEffectLVL);
    PlayerPrefs.SetFloat ("CarrotEffect", Stats.CarrotEffect);
    PlayerPrefs.SetInt ("CarrotEffectUpgradeCost", Stats.CarrotEffectUpgradeCost);
    PlayerPrefs.SetInt ("UmbrellaDurabilityLvL", Stats.UmbrellaDurabilityLVL);
    PlayerPrefs.SetFloat ("UmbrellaDurability", Stats.UmbrellaDurability);
    PlayerPrefs.SetInt ("UmbrellaDurabilityUpgradeCost", Stats.UmbrellaDurabilityUpgradeCost);
    PlayerPrefs.SetInt ("UmbrellaSizeLvL", Stats.UmbrellaSizeLVL);
    PlayerPrefs.SetFloat ("UmbrellaSize", Stats.UmbrellaSize);
    PlayerPrefs.SetInt ("UmbrellaSizeUpgadeCost", Stats.UmbrellaSizeUpgradeCost);
    PlayerPrefs.SetInt ("Tree1Bought", Stats.Tree1Bought);
    PlayerPrefs.SetInt ("Tree1LvL", Stats.Tree1SizeLVL);
    PlayerPrefs.SetFloat ("Tree1Size", Stats.Tree1Size);
    PlayerPrefs.SetInt ("Tree1UpgradeCost", Stats.Tree1SizeUpgradeCost);
    PlayerPrefs.SetInt ("Tree2Bought", Stats.Tree2Bought);
    PlayerPrefs.SetInt ("Tree2LvL", Stats.Tree2SizeLVL);
    PlayerPrefs.SetFloat ("Tree2Size", Stats.Tree2Size);
    PlayerPrefs.SetInt ("Tree2UpgradeCost", Stats.Tree2SizeUpgradeCost);
    PlayerPrefs.SetInt ("Tree3Bought", Stats.Tree3Bought);
    PlayerPrefs.SetInt ("Tree3LvL", Stats.Tree3SizeLVL);
    PlayerPrefs.SetFloat ("Tree3Size", Stats.Tree3Size);
    PlayerPrefs.SetInt ("Tree3UpgradeCost", Stats.Tree3SizeUpgradeCost);
    PlayerPrefs.SetInt ("BuyTreeCost", Stats.BuyTreesCost);*/

}
void SaveGame (){
    PlayerPrefs.Save ();
}

0 个答案:

没有答案