playerpref steps

This commit is contained in:
asleal2 2018-04-26 04:38:54 -05:00
parent 908c88ed85
commit df378ecc50

View file

@ -14,7 +14,6 @@ public class GetGoals : MonoBehaviour {
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string prefKey; public string prefKey;
public float goalValue;
//Progress Bar... //Progress Bar...
public float barDisplay; //current progress public float barDisplay; //current progress
@ -24,16 +23,23 @@ public class GetGoals : MonoBehaviour {
//Pedometer //Pedometer
private Pedometer pedometer; private Pedometer pedometer;
int userSteps; int userSteps;
int userPoints;
double userDistance; double userDistance;
int totalSteps = 100; int stepsGoal = 100;
public Text stepText; public Text stepText;
public Text pointsText;
private int savedSteps; private int savedSteps;
private int savedPoints;
void OnStep (int steps, double distance) { void OnStep (int steps, double distance) {
userDistance = (distance * 3.28084); userDistance = (distance * 3.28084);
userSteps = steps + savedSteps; userSteps = steps + savedSteps;
PlayerPrefs.SetInt("currentSteps",userSteps); PlayerPrefs.SetInt("currentSteps",userSteps);
stepText.text = userSteps.ToString (); stepText.text = userSteps.ToString ();
userPoints = steps*5 + savedPoints;
PlayerPrefs.SetInt("totalPoints",userPoints);
pointsText.text = "Points: " + userPoints.ToString ();
} }
private void OnDisable () { private void OnDisable () {
@ -47,11 +53,22 @@ public class GetGoals : MonoBehaviour {
void Start () { void Start () {
savedSteps = PlayerPrefs.GetInt("currentSteps"); savedSteps = PlayerPrefs.GetInt("currentSteps");
savedPoints = PlayerPrefs.GetInt("totalPoints");
// Create a new pedometer // Create a new pedometer
pedometer = new Pedometer(OnStep); pedometer = new Pedometer(OnStep);
// Reset UI // Reset UI
stepText.text = savedSteps.ToString (); stepText.text = savedSteps.ToString ();
if(PlayerPrefs.HasKey("totalPoints"))
{
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
}
else
{
PlayerPrefs.SetInt("totalPoints", 0);
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
}
userSteps = savedSteps; userSteps = savedSteps;
userPoints = savedPoints;
//OnStep(savedSteps, 0); //OnStep(savedSteps, 0);
Debug.Log(savedSteps); Debug.Log(savedSteps);
@ -65,7 +82,6 @@ public class GetGoals : MonoBehaviour {
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
Debug.Log(goalDayStr); Debug.Log(goalDayStr);
Debug.Log("hauaouou");
if(prefKey == "daily") if(prefKey == "daily")
savePersistantGoalDate("daily"); savePersistantGoalDate("daily");
@ -111,7 +127,7 @@ public class GetGoals : MonoBehaviour {
//needs the total required points for this goal //needs the total required points for this goal
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
//barDisplay = Time.time*0.05f; //put actual progress here (current/total) //barDisplay = Time.time*0.05f; //put actual progress here (current/total)
barDisplay = (float)userSteps/(float)totalSteps; barDisplay = (float)userSteps/(float)stepsGoal;
//failed to complete goal //failed to complete goal
if(currentDayStr != goalDayStr) if(currentDayStr != goalDayStr)
@ -133,8 +149,14 @@ public class GetGoals : MonoBehaviour {
userSteps = 0; userSteps = 0;
PlayerPrefs.SetInt("currentSteps", userSteps); PlayerPrefs.SetInt("currentSteps", userSteps);
savedSteps = 0; savedSteps = 0;
OnStep(0,0); //OnStep(0,0);
stepText.text = userSteps.ToString ();
//destroy the goal and set a new one? //destroy the goal and set a new one?
savedPoints += stepsGoal*10;
PlayerPrefs.SetInt("totalPoints", savedPoints);
stepText.text = PlayerPrefs.GetInt("totalPoints").ToString ();
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
} }
//only applies if "daily" goal //only applies if "daily" goal