diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 51560bd..c4bd64d 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -28,6 +28,8 @@ public class GameManager : MonoBehaviour { } + + void OnEnable() { Load(); @@ -38,6 +40,20 @@ public class GameManager : MonoBehaviour { Save(); } + void OnApplicationFocus(bool pauseStatus) + { + if (pauseStatus) + { + //your app is NO LONGER in the background + Load(); + } + else + { + //your app is now in the background + Save(); + } + } + void OnApplicationQuit() { Save(); @@ -62,7 +78,7 @@ public class GameManager : MonoBehaviour { data.speed = currentSpeed; data.increment = currentIncrement; data.rotationsPerSec = rotationPerSec; - data.currentTime = DateTime.Now; + data.currentTime = System.DateTime.Now; bf.Serialize(file, data); file.Close(); @@ -85,9 +101,8 @@ public class GameManager : MonoBehaviour { GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp = data.experience; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement = data.requirement; - DateTime loadTime = DateTime.Now; + DateTime loadTime = System.DateTime.Now; int secondsPassed = GetIdleTime(data.currentTime, loadTime); - float radianSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed * Mathf.Deg2Rad; float idleExp = (data.rotationsPerSec * secondsPassed) * data.increment; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp += idleExp;