Guest User

Untitled

a guest
Jan 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. public GameObject happinessText;
  2. public GameObject hungerText;
  3.  
  4. public GameObject robot;
  5. // Update is called once per frame
  6. void Update()
  7. {
  8. happinessText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().happiness;
  9. hungerText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().hunger;
  10. //happinessText.GetComponent<Text>().text = "" + robot.GetComponent<Robot>().happiness;
  11. }
  12.  
  13. public int _hunger;
  14. public int _happiness;
  15.  
  16.  
  17. void Start()
  18. {
  19. PlayerPrefs.SetString("then", "05/06/2016 11:20:12");
  20. updateStatus();
  21. }
  22.  
  23.  
  24.  
  25. void updateStatus()
  26. {
  27. if (!PlayerPrefs.HasKey("_hunger"))
  28. {
  29. _hunger = 100;
  30. PlayerPrefs.SetInt("_hunger", _hunger);
  31.  
  32. } else {
  33. _hunger = PlayerPrefs.GetInt("_hunger");
  34. }
  35.  
  36. if (!PlayerPrefs.HasKey("_happiness"))
  37. {
  38. _happiness = 100;
  39. PlayerPrefs.SetInt("_happiness", _happiness);
  40.  
  41. } else {
  42.  
  43. _happiness = PlayerPrefs.GetInt("_happiness");
  44.  
  45. }
  46.  
  47. if (!PlayerPrefs.HasKey("then")) //{
  48. PlayerPrefs.SetString("then", getStringTime());
  49.  
  50. TimeSpan ts = GetTimeSpan();
  51.  
  52. _hunger -= (int)(ts.TotalHours * 2);
  53. if (_hunger < 0)
  54. _hunger = 0;
  55.  
  56. _happiness -= (int)((100 - _hunger) * ts.TotalHours / 5);
  57.  
  58. if (_happiness < 0)
  59. _happiness = 0;
  60.  
  61. }
  62.  
  63. public int hunger
  64. {
  65. [OnSerialized]
  66. get { return _hunger; }
  67. set { _hunger = value; }
  68. }
  69.  
  70. public int happiness
  71. {
  72. [OnSerialized]
  73. get { return _happiness; }
  74. set { _happiness = value; }
  75. }
Add Comment
Please, Sign In to add comment