Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System;
- [System.Serializable]
- public class UpDataShop
- {
- public Text upName;
- public Text upPrise;
- public int Prise;
- public int upModule;
- public int prisePlus;
- public Button But;
- }
- public class GameScript : MonoBehaviour {
- [Header("Стандарт")]
- int score = 0;
- int module = 0;
- int workerCount = 0;
- int workersLvl = 1;
- public Text scoreText;
- [Header("Магазин"), Space(10)]
- public UpDataShop[] Shop;
- public GameObject shopPanel;
- private Save SaveGame = new Save();
- void Awake()
- {
- if (PlayerPrefs.HasKey("Saves"))
- {
- SaveGame = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("Saves"));
- score = SaveGame.scores;
- module = SaveGame.modules;
- workerCount = SaveGame.workerCounts;
- workersLvl = SaveGame.workersLvls;
- for (int i = 0; i < Shop.Length; i++)
- {
- Shop[i].Prise = SaveGame.Prises[i];
- Shop[i].upModule = SaveGame.upModules[i];
- Shop[i].prisePlus = SaveGame.prisePluss[i];
- }
- DateTime dt = new DateTime(SaveGame.Date[0]);
- TimeSpan ts = DateTime.Now - dt;
- }
- }
- IEnumerator PlusPerSecond()
- {
- while (true)
- {
- score += (workerCount * workersLvl);
- yield return new WaitForSeconds(1);
- }
- }
- public void OnShopButtonCklick(int id)
- {
- if (id == -1)
- shopPanel.SetActive(!shopPanel.activeSelf);
- if (id == 0)
- {
- if (score >= Shop[id].Prise)
- {
- score -= Shop[id].Prise;
- module += Shop[id].upModule;
- Shop[id].Prise *= Shop[id].prisePlus;
- }
- }
- if (id == 1)
- {
- if (score >= Shop[id].Prise)
- {
- score -= Shop[id].Prise;
- workerCount += Shop[id].upModule;
- Shop[id].Prise *= Shop[id].prisePlus;
- }
- }
- if (id == 2)
- {
- if (score >= Shop[id].Prise)
- {
- score -= Shop[id].Prise;
- workersLvl += Shop[id].upModule;
- Shop[id].Prise *= Shop[id].prisePlus;
- }
- }
- }
- public void OnClick(int id)
- {
- if (id == 0)
- score += (1 + module);
- }
- void Update()
- {
- scoreText.text = "Score: " + score.ToString() + '$';
- for (int a = 0; a < Shop.Length; a++)
- {
- Shop[a].upPrise.text = Shop[a].Prise.ToString() + '$';
- if (Shop[a].Prise > score)
- {
- Shop[a].But.interactable = false;
- }
- else
- {
- Shop[a].But.interactable = true;
- }
- }
- }
- void Start()
- {
- StartCoroutine(PlusPerSecond());
- }
- #if UNITY_ANDROID && !UNITY_EDITOR
- void OnApplicationPaused()
- {
- SaveGame.Prises = new int[Shop.Length];
- SaveGame.upModules = new int[Shop.Length];
- SaveGame.prisePluss = new int[Shop.Length];
- for (int i = 0; i < Shop.Length; i++)
- {
- SaveGame.Prises[i] = Shop[i].Prise;
- SaveGame.upModules[i] = Shop[i].upModule;
- SaveGame.prisePluss[i] = Shop[i].prisePlus;
- }
- SaveGame.scores = score;
- SaveGame.modules = module;
- SaveGame.workerCounts = workerCount;
- SaveGame.workersLvls = workersLvl;
- PlayerPrefs.SetString("Saves", JsonUtility.ToJson(SaveGame));
- }
- #else
- void OnApplicationQuit()
- {
- SaveGame.Prises = new int[Shop.Length];
- SaveGame.upModules = new int[Shop.Length];
- SaveGame.prisePluss = new int[Shop.Length];
- for (int i = 0; i < Shop.Length; i++)
- {
- SaveGame.Prises[i] = Shop[i].Prise;
- SaveGame.upModules[i] = Shop[i].upModule;
- SaveGame.prisePluss[i] = Shop[i].prisePlus;
- }
- SaveGame.scores = score;
- SaveGame.modules = module;
- SaveGame.workerCounts = workerCount;
- SaveGame.workersLvls = workersLvl;
- SaveGame.Date[0] = DateTime.Now.Second;
- PlayerPrefs.SetString("Saves", JsonUtility.ToJson(SaveGame));
- }
- #endif
- }
- [System.Serializable]
- public class Save
- {
- public int scores;
- public int modules;
- public int workerCounts;
- public int workersLvls;
- public int[] Prises;
- public int[] upModules;
- public int[] prisePluss;
- public int[] Date;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement