示例#1
0
    //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
    }
示例#2
0
 void Update()
 {
     //If the player didn't run into an encounter, update the step text
     if (!encounterActive)
     {
         pedometer.LoadStepToday();
         int newSteps = pedometer.GetStepToday();
         if (steps < newSteps)
         {
             steps += (newSteps - steps);
         }
         stepDisplay.text     = "" + steps;
         currencyDisplay.text = GameObject.Find("Inventory").GetComponent <Inventory>().gold.ToString();
     }
 }