Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Gold : MonoBehaviour {
- GameManager gm;
- public UnityEngine.UI.Text goldDisplay;
- private float _gold;
- void Start ()
- {
- gm = GameObject.Find("Game Manager").GetComponent<GameManager>();
- gm.Load();
- }
- void Update ()
- {
- UpdateGoldDisplay();
- }
- public void SetGold(float x)
- {
- _gold = x;
- }
- public float GetGold()
- {
- return _gold;
- }
- public void UpdateGoldDisplay()
- {
- SetGoldDisplay(GetGold().ToString());
- }
- public void SetGoldDisplay(string x)
- {
- goldDisplay.text = x;
- }
- }
- using UnityEngine;
- using System.Collections;
- public class GameManager : MonoBehaviour {
- GameObject GO_Player;
- Gold gold;
- void Start ()
- {
- GO_Player = GameObject.Find ("Player");
- gold = GO_Player.GetComponent<Gold>();
- }
- void OnApplicationQuiot()
- {
- Save();
- }
- public void Load()
- {
- gold.SetGold(PlayerPrefs.GetFloat("gold", 50));
- }
- private void Save()
- {
- PlayerPrefs.SetFloat("gold", 1);
- }
- public void DeleteSaves()
- {
- PlayerPrefs.SetFloat("gold", 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement