playerpref steps
This commit is contained in:
parent
908c88ed85
commit
df378ecc50
1 changed files with 27 additions and 5 deletions
|
@ -14,7 +14,6 @@ public class GetGoals : MonoBehaviour {
|
|||
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
public string prefKey;
|
||||
public float goalValue;
|
||||
|
||||
//Progress Bar...
|
||||
public float barDisplay; //current progress
|
||||
|
@ -24,16 +23,23 @@ public class GetGoals : MonoBehaviour {
|
|||
//Pedometer
|
||||
private Pedometer pedometer;
|
||||
int userSteps;
|
||||
int userPoints;
|
||||
double userDistance;
|
||||
int totalSteps = 100;
|
||||
int stepsGoal = 100;
|
||||
public Text stepText;
|
||||
public Text pointsText;
|
||||
private int savedSteps;
|
||||
private int savedPoints;
|
||||
|
||||
void OnStep (int steps, double distance) {
|
||||
userDistance = (distance * 3.28084);
|
||||
userSteps = steps + savedSteps;
|
||||
PlayerPrefs.SetInt("currentSteps",userSteps);
|
||||
stepText.text = userSteps.ToString ();
|
||||
|
||||
userPoints = steps*5 + savedPoints;
|
||||
PlayerPrefs.SetInt("totalPoints",userPoints);
|
||||
pointsText.text = "Points: " + userPoints.ToString ();
|
||||
}
|
||||
|
||||
private void OnDisable () {
|
||||
|
@ -47,11 +53,22 @@ public class GetGoals : MonoBehaviour {
|
|||
|
||||
void Start () {
|
||||
savedSteps = PlayerPrefs.GetInt("currentSteps");
|
||||
savedPoints = PlayerPrefs.GetInt("totalPoints");
|
||||
// Create a new pedometer
|
||||
pedometer = new Pedometer(OnStep);
|
||||
// Reset UI
|
||||
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;
|
||||
userPoints = savedPoints;
|
||||
|
||||
//OnStep(savedSteps, 0);
|
||||
Debug.Log(savedSteps);
|
||||
|
@ -65,7 +82,6 @@ public class GetGoals : MonoBehaviour {
|
|||
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
Debug.Log(goalDayStr);
|
||||
Debug.Log("hauaouou");
|
||||
|
||||
if(prefKey == "daily")
|
||||
savePersistantGoalDate("daily");
|
||||
|
@ -111,7 +127,7 @@ public class GetGoals : MonoBehaviour {
|
|||
//needs the total required points for this goal
|
||||
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||
//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
|
||||
if(currentDayStr != goalDayStr)
|
||||
|
@ -133,8 +149,14 @@ public class GetGoals : MonoBehaviour {
|
|||
userSteps = 0;
|
||||
PlayerPrefs.SetInt("currentSteps", userSteps);
|
||||
savedSteps = 0;
|
||||
OnStep(0,0);
|
||||
//OnStep(0,0);
|
||||
stepText.text = userSteps.ToString ();
|
||||
|
||||
//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
|
||||
|
|
Reference in a new issue