diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 534f596..87f6744 100644 Binary files a/Assets/Scenes/Main.unity and b/Assets/Scenes/Main.unity differ diff --git a/Assets/Scripts/ExperienceBar.cs b/Assets/Scripts/ExperienceBar.cs index 768a1b2..6d57e9e 100644 --- a/Assets/Scripts/ExperienceBar.cs +++ b/Assets/Scripts/ExperienceBar.cs @@ -7,17 +7,16 @@ public class ExperienceBar : MonoBehaviour { // Eventually.. public RectTransform gainedExp //Array used as expRequired[leveldesired] - [SerializeField] - private int level = 1; - [SerializeField] - private float expObtained = 0; - [SerializeField] - private float expRequired = 100; + + //playerdata - needs saved + public int currentLevel = 1; + public float currentExp = 0; + public float currentRequirement = 100; + public GameObject currentLevelText; + [SerializeField] private float fillAmount; [SerializeField] - private GameObject levelText; - [SerializeField] private Image expBarSprite; [SerializeField] private float lerpSpeed; @@ -32,11 +31,17 @@ public class ExperienceBar : MonoBehaviour { // Use this for initialization void Start () { - fillAmount = 0; + fillAmount = currentExp / currentRequirement; } // Update is called once per frame void Update () { + fillAmount = currentExp / currentRequirement; + + + if (currentLevelText.GetComponent().text != currentLevel.ToString()){ + currentLevelText.GetComponent().text = currentLevel.ToString(); + } if (fillAmount != expBarSprite.fillAmount) { @@ -47,7 +52,7 @@ public class ExperienceBar : MonoBehaviour { if (expBarSprite.fillAmount >= 1.0f) { LevelUp(); - clicksNeeded = (expRequired - expObtained) / Increment; + clicksNeeded = (currentRequirement - currentExp) / Increment; fillAmount = 0; } } @@ -55,28 +60,28 @@ public class ExperienceBar : MonoBehaviour { public void ExpMore() { ++clicks; - expObtained = expObtained + Increment; - fillAmount = (expObtained / expRequired); + currentExp = currentExp + Increment; + fillAmount = currentExp / currentRequirement; Debug.Log("fillAmount = " + fillAmount); } public void LevelUp() { - ++level; - levelText.GetComponent().text = level.ToString(); - previousExpRequired = expRequired; - expObtained = 0; - expRequired = Mathf.Pow(expRequired, 1.05f); + ++currentLevel; + currentLevelText.GetComponent().text = currentLevel.ToString(); + previousExpRequired = currentRequirement; + currentExp = 0; + currentRequirement = Mathf.Pow(currentRequirement, 1.05f); GameObject.FindGameObjectWithTag("Player").GetComponent().RaiseRotationSpeed(); } public void ResetExp() { - level = 1; - levelText.GetComponent().text = level.ToString(); + currentLevel = 1; + currentLevelText.GetComponent().text = currentLevel.ToString(); fillAmount = 0; - expObtained = 0; - expRequired = 100; + currentExp = 0; + currentRequirement = 100; clicksNeeded = 10; clicks = 0; } @@ -84,9 +89,17 @@ public class ExperienceBar : MonoBehaviour { public void ExpLess() { --clicks; - expObtained = expObtained - Increment; - fillAmount = (expObtained / expRequired); + currentExp = currentExp - Increment; + fillAmount = (currentExp / currentRequirement); Debug.Log("fillAmount = " + fillAmount); } + public float GetExperience() + { + float currentExp; + currentExp = this.currentExp; + return currentExp; + } + + } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs new file mode 100644 index 0000000..7209a28 --- /dev/null +++ b/Assets/Scripts/GameManager.cs @@ -0,0 +1,95 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System; +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; + + +public class GameManager : MonoBehaviour { + + //Used to save playerdata + //Serializable tells unity it can save to a file + [Serializable] + private class PlayerData + { + public int level; + public float experience; + public float requirement; + public float speed; + public float increment; + } + + + // Use this for initialization + void Start () { + Load(); + } + + // Update is called once per frame + void Update () { + + } + + void OnEnable() + { + Load(); + } + + void OnApplicationPause() + { + Save(); + } + + void OnApplicationQuit() + { + Save(); + } + + public void Save() + { + BinaryFormatter bf = new BinaryFormatter(); + FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat"); + + int currentLevel = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel; + float currentExp = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp; + float currentRequirement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement; + float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed; + float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement; + + PlayerData data = new PlayerData(); + data.level = currentLevel; + data.experience = currentExp; + data.requirement = currentRequirement; + data.speed = currentSpeed; + data.increment = currentIncrement; + + bf.Serialize(file, data); + file.Close(); + Debug.Log("Saved"); + + } + + public void Load() + { + if (File.Exists(Application.persistentDataPath + "/playerInfo.dat")) + { + BinaryFormatter bf = new BinaryFormatter(); + FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); + PlayerData data = (PlayerData)bf.Deserialize(file); + file.Close(); + + GameObject.FindGameObjectWithTag("Player").GetComponent().currentSpeed = data.speed; + GameObject.FindGameObjectWithTag("Player").GetComponent().currentIncrement = data.increment; + GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentLevel = data.level; + GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentExp = data.experience; + GameObject.FindGameObjectWithTag("ExpGained").GetComponent().currentRequirement = data.requirement; + Debug.Log("Loaded"); + + + + } + + } + +} diff --git a/Assets/Scripts/GameManager.cs.meta b/Assets/Scripts/GameManager.cs.meta new file mode 100644 index 0000000..697d467 --- /dev/null +++ b/Assets/Scripts/GameManager.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2da23f5b35feb9749839423cfa5b61b2 +timeCreated: 1503806997 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SpinningCube.cs b/Assets/Scripts/SpinningCube.cs index ce4f7be..9c7c0d6 100644 --- a/Assets/Scripts/SpinningCube.cs +++ b/Assets/Scripts/SpinningCube.cs @@ -3,8 +3,10 @@ using System.Collections; public class SpinningCube : MonoBehaviour { - public float m_Speed = 20f; - public float increments = 10f; + + //Playerdata -- Needs saved + public float currentSpeed = 20f; + public float currentIncrement = 10f; private string RotationDirection = "Up"; @@ -52,21 +54,21 @@ public class SpinningCube : MonoBehaviour public void RaiseRotationSpeed() { - m_Speed = m_Speed + increments; + currentSpeed = currentSpeed + currentIncrement; - Debug.Log("Rotation Speed: " + m_Speed); + Debug.Log("Rotation Speed: " + currentSpeed); } public void LowerRotationSpeed() { - m_Speed = m_Speed - increments; + currentSpeed = currentSpeed - currentIncrement; - Debug.Log("Rotation Speed: " + m_Speed); + Debug.Log("Rotation Speed: " + currentSpeed); } public void ResetRotationSpeed() { - m_Speed = 20.0f; + currentSpeed = 20.0f; Debug.Log("Rotation Speed Reset"); } @@ -111,16 +113,11 @@ public class SpinningCube : MonoBehaviour gameObject.GetComponent().material.color = Color.cyan; } - public void Start() - { - Vector3 rotationOrigin = GameObject.FindGameObjectWithTag("Player").transform.rotation.eulerAngles; - } - void FixedUpdate() { //Set angle1 = eulerAngle of axis being rotated prior to applying rotation angle1 = this.gameObject.transform.rotation.eulerAngles.y; - transform.Rotate(m_RotationDirection * Time.deltaTime * m_Speed); + transform.Rotate(m_RotationDirection * Time.deltaTime * currentSpeed); //angle2 = eulerAngle of axis after rotation applied angle2 = this.gameObject.transform.rotation.eulerAngles.y; //Difference between angle2 and angle1, how much the object rotated between frames @@ -132,7 +129,7 @@ public class SpinningCube : MonoBehaviour //If object has rotated 20 degrees (m_speed = 20), when angle1 = 350, && angle2 = 10 //angle2(10)-angle1(350) = -340 //Object has rotated past 360 - if ((m_Speed > 0) && (angledif < 0)) + if ((currentSpeed > 0) && (angledif < 0)) { ++rotations; GameObject.FindGameObjectWithTag("ExpGained").GetComponent().ExpMore(); diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 7f8b683..29bd02d 100644 Binary files a/ProjectSettings/QualitySettings.asset and b/ProjectSettings/QualitySettings.asset differ