From a04e1e122513b004a8ca757c4ef51a19d9f5e225 Mon Sep 17 00:00:00 2001 From: Shaun M Reed Date: Mon, 4 Sep 2017 14:56:21 -0400 Subject: [PATCH] Fixed idleExp not working on android Fixed idleExp only working through unity editor, now works on application built to an android device through OnApplicationFocus() --- Assets/Scripts/GameManager.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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;