diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index b1192c2..1761c96 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -18,19 +18,15 @@ public class GameManager : MonoBehaviour { public float requirement; public float speed; public float increment; + public DateTime currentTime; + } - // Update is called once per frame - void Update () { + // Update is called once per frame + void Update () { } - - // Use this for initialization - void Start () { - Load(); - } - void OnEnable() { Load(); @@ -63,6 +59,7 @@ public class GameManager : MonoBehaviour { data.requirement = currentRequirement; data.speed = currentSpeed; data.increment = currentIncrement; + data.currentTime = DateTime.Now; bf.Serialize(file, data); file.Close(); @@ -83,7 +80,42 @@ public class GameManager : MonoBehaviour { GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel = data.level; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp = data.experience; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement = data.requirement; + + DateTime loadTime = DateTime.Now; + int secondsPassed = GetIdleRewards(data.currentTime, loadTime); + float radianSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed * Mathf.Deg2Rad; + float idleExp = radianSpeed * secondsPassed; + GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp += idleExp; + Debug.Log("Loaded"); + Debug.Log("idleExp: " + idleExp); } } + + public int GetIdleRewards(DateTime saveTime, DateTime loadTime) + { + int daysPassed = 0; + int hoursPassed = 0; + int minutesPassed = 0; + int secondsPassed = 0; + + for (int monthSaved = saveTime.Month; monthSaved < loadTime.Month; ++monthSaved) + { + daysPassed += 30; + } + daysPassed += loadTime.Day - saveTime.Day; + + hoursPassed = daysPassed * 24; + hoursPassed += loadTime.Hour - saveTime.Hour; + + minutesPassed = hoursPassed * 60; + minutesPassed += loadTime.Minute - saveTime.Minute; + + secondsPassed = minutesPassed * 60; + secondsPassed += loadTime.Second - saveTime.Second; + + Debug.Log("Seconds Passed: " + secondsPassed); + return secondsPassed; + } + } diff --git a/Assets/Scripts/SpinningCube.cs b/Assets/Scripts/SpinningCube.cs index 13a45a5..009451a 100644 --- a/Assets/Scripts/SpinningCube.cs +++ b/Assets/Scripts/SpinningCube.cs @@ -8,7 +8,6 @@ public class SpinningCube : MonoBehaviour public float currentSpeed = 20f; public float currentIncrement = 10f; - private string RotationDirection = "Up"; private Vector3 m_RotationDirection = Vector3.up; private Vector3 rotationOrigin;