当我在游戏编辑器或手机上启动我的游戏时,它会在2-3秒内出现故障,并调用函数OnApplicationPause
。但是当我关闭应用程序/暂停编辑器时,它不会调用。这很糟糕,所以该怎么解决呢?以下是函数代码:
void OnApplicationPause()
{
DateTime time = DateTime.Now;
SaveVariablesInClass();
PlayerPrefs.SetString("SV", JsonUtility.ToJson(save)); //saves special class
}
void SaveVariablesInClass()
{
save.Bananas = bananas;
save.GoldBananas = goldBananas;
save.TwoBananasSpawnChance = twoBananasSpawnChance;
save.HigherBananaLevelChance = higherBananaLevelChance;
save.SimpleBananaStormChance = simpleBananaStormChance;
save.GoldBananaChance = goldBananaChance;
save.TwoGoldBananaChance = twoGoldBananaChance;
save.offlineEfficiency = offlineEfficiency;
save.offlineProductionTime = offlineProductionTime;
save.goldCoefficient = goldCoefficient;
save.BonusLevels = bonusLevels;
save.GoldBonusLevels = goldBonusLevels;
save.SimpleBonusLevelPrices = simpleBonusLevelPrices;
save.GoldBonusLevelPrices = goldBonusLevelPrices;
save.simpleMaxLevels = simpleMaxLevels;
save.goldMaxLevels = goldMaxLevels;
save.time = time.ToString();
save.CurrentSimpleBonus1 = currentSimpleBonus1;
save.LaunchedGame = launchedGame;
}
OnApplicationPause
一个bool
参数并在其为false
时跳过吗? - derHugoOnApplicationPause()
在真正的暂停中也无法工作,游戏开始时的延迟取决于渲染。详细信息请参见:https://imgur.com/a/LSxmLX3 - JediMan