Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameObject happinessText;
- public GameObject hungerText;
- public GameObject robot;
- // Update is called once per frame
- void Update()
- {
- happinessText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().happiness;
- hungerText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().hunger;
- //happinessText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().happiness;
- }
- public int _hunger;
- public int _happiness;
- void Start()
- {
- PlayerPrefs.SetString("then", "05/06/2016 11:20:12");
- updateStatus();
- }
- void updateStatus()
- {
- if (!PlayerPrefs.HasKey("_hunger"))
- {
- _hunger = 100;
- PlayerPrefs.SetInt("_hunger", _hunger);
- } else {
- _hunger = PlayerPrefs.GetInt("_hunger");
- }
- if (!PlayerPrefs.HasKey("_happiness"))
- {
- _happiness = 100;
- PlayerPrefs.SetInt("_happiness", _happiness);
- } else {
- _happiness = PlayerPrefs.GetInt("_happiness");
- }
- if (!PlayerPrefs.HasKey("then")) //{
- PlayerPrefs.SetString("then", getStringTime());
- TimeSpan ts = GetTimeSpan();
- _hunger -= (int)(ts.TotalHours * 2);
- if (_hunger < 0)
- _hunger = 0;
- _happiness -= (int)((100 - _hunger) * ts.TotalHours / 5);
- if (_happiness < 0)
- _happiness = 0;
- }
- public int hunger
- {
- [OnSerialized]
- get { return _hunger; }
- set { _hunger = value; }
- }
- public int happiness
- {
- [OnSerialized]
- get { return _happiness; }
- set { _happiness = value; }
- }
Add Comment
Please, Sign In to add comment