// the pedometer service is not auto start // call this to start the service // and don't worry after you close or quit the unity3d application the // pedometer service will start and run again public void StartPedometerService() { // here you start and pass the sensor delay that you want to use pedometerPlugin.StartPedometerService(SensorDelay.SENSOR_DELAY_FASTEST); UpdateStepDetectorStatus("Service Started"); Debug.Log(demoName + "StartPedometerService has been called"); }
//Runs each time game starts public void Start() { pedometerPlugin = PedometerPlugin.GetInstance(); pedometerPlugin.SetDebug(0); pedometerPlugin.Init(); pedometerPlugin.StartPedometerService(SensorDelay.SENSOR_DELAY_FASTEST); steps = pedometerPlugin.GetStepToday(); //get time as ascii value int d1 = DateTime.Now.Hour; System.DateTime epochStart = new System.DateTime(2018, 1, 1, 0, 0, 0, System.DateTimeKind.Utc); int cur_time = (int)(System.DateTime.UtcNow - epochStart).TotalHours; //check last time health was calculated float healthDeduction = PlayerPrefs.GetFloat("health") - (healthDrainRate * (cur_time - PlayerPrefs.GetFloat("timeOfLastHealthCheck"))); //Steps should be zero if its a new day int oldSteps = PlayerPrefs.GetInt("steps"); if (oldSteps > steps) { oldSteps = steps; PlayerPrefs.SetInt("steps", steps); } //reduce health PlayerPrefs.SetFloat("health", healthDeduction); PlayerPrefs.SetFloat("timeOfLastHealthCheck", cur_time); //Load scene from PlayerPrefs GameObject sliderObj = GameObject.Find("HealthSlider"); if (sliderObj != null) { Slider healthSlider = sliderObj.GetComponent <Slider> (); healthSlider.value = PlayerPrefs.GetFloat("health"); } else { Debug.Log("Slider is null"); } //Load number of berries in button GameObject feedObject = GameObject.Find("berryCount"); if (feedObject != null) { Text berriesText = feedObject.GetComponent <Text> (); feedObject.GetComponentInChildren <Text>().text = "" + PlayerPrefs.GetInt("berries"); } //load slider }
void Start() { //Get steps from save file steps = GameObject.Find("SaveManager").GetComponent <SaveManager>().state.steps; //Gets instance pedometer = PedometerPlugin.GetInstance(); //Hides debug messages when set to zero pedometer.SetDebug(0); //Initaialize pedometer.Init(); pedometer.StartPedometerService(sensor); }