// Load the data when the player returns to the game void LoadData() { gameManager.ProcessBegin(); string timeQuit = PlayerPrefs.GetString("TimeQuit"); // Do we have data about the last time the user played? if (timeQuit != "") { double difference = gameManager.TimeNow() - double.Parse(PlayerPrefs.GetString("TimeQuit")); int secondsGone = (int)Mathf.Floor((float)difference); // Tell the buyables to check their playerprefs to load data foreach (BuyableData data in idles.idles) { data.LoadData(secondsGone); } // We only want the earnings made for 'x' hours whilst the player was away; let's see which is the smaller of the two int maxSeconds = gameManager.idleHours * 3600; secondsGone = Mathf.Min(secondsGone, maxSeconds); // Calculate the amount earned offline double idleEarnings = moneyManager.ActualIdleProfit(); // Tell other scripts we've loaded, incase they want to do anything with the new data if (onLoaded != null) { onLoaded(); } // Tell other scripts (typically a UI-handler) that we've calculated some away profits if (onAwayProfitsCalculated != null) { onAwayProfitsCalculated(secondsGone, idleEarnings); } } gameManager.ProcessComplete(); }