Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Gold : MonoBehaviour {
  5. GameManager gm;
  6.  
  7. public UnityEngine.UI.Text goldDisplay;
  8.  
  9. private float _gold;
  10.  
  11. void Start ()
  12. {
  13. gm = GameObject.Find("Game Manager").GetComponent<GameManager>();
  14. gm.Load();
  15. }
  16.  
  17. void Update ()
  18. {
  19. UpdateGoldDisplay();
  20. }
  21.  
  22. public void SetGold(float x)
  23. {
  24. _gold = x;
  25. }
  26.  
  27. public float GetGold()
  28. {
  29. return _gold;
  30. }
  31.  
  32. public void UpdateGoldDisplay()
  33. {
  34. SetGoldDisplay(GetGold().ToString());
  35. }
  36. public void SetGoldDisplay(string x)
  37. {
  38. goldDisplay.text = x;
  39. }
  40. }
  41.  
  42. using UnityEngine;
  43. using System.Collections;
  44.  
  45. public class GameManager : MonoBehaviour {
  46.  
  47. GameObject GO_Player;
  48. Gold gold;
  49.  
  50. void Start ()
  51. {
  52. GO_Player = GameObject.Find ("Player");
  53. gold = GO_Player.GetComponent<Gold>();
  54. }
  55.  
  56. void OnApplicationQuiot()
  57. {
  58. Save();
  59. }
  60. public void Load()
  61. {
  62. gold.SetGold(PlayerPrefs.GetFloat("gold", 50));
  63. }
  64. private void Save()
  65. {
  66. PlayerPrefs.SetFloat("gold", 1);
  67. }
  68.  
  69. public void DeleteSaves()
  70. {
  71. PlayerPrefs.SetFloat("gold", 0);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement