pelemexa

Untitled

Jul 27th, 2021
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6.  
  7. public class Game : MonoBehaviour
  8. {
  9. [SerializeField] int Score;
  10. public int[] CostInt;
  11. public int ClickScore = 1;
  12. public int[] CostBonus;
  13. public int TotalBonus;
  14.  
  15. public GameObject ShopPan;
  16. public GameObject BonusPan;
  17.  
  18. public Text[] CostText;
  19. public Text ScoreText;
  20.  
  21. public Save sv = new Save();
  22.  
  23. public void Awake()
  24. {
  25. if(PlayerPrefs.HasKey("SV"))
  26. {
  27. sv = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("SV"));
  28. Score = sv.Score;
  29. ClickScore = sv.ClickScore;
  30.  
  31. for(int i = 0; i < 1; i++)
  32. {
  33. CostBonus[i] = sv.CostBonus [i];
  34. TotalBonus += sv.CostBonus[i];
  35. }
  36.  
  37. for(int i = 0; i < 2; i++)
  38. {
  39. sv.CostInt[i] = sv.CostInt [i];
  40. CostText[i].text = sv.CostInt[i] + "$";
  41. }
  42. }
  43. }
  44.  
  45. public void Start()
  46. {
  47. StartCoroutine(BonusShop());
  48.  
  49. DateTime dt = new DateTime(sv.Date[0], sv.Date[1], sv.Date[2], sv.Date[3], sv.Date[4], sv.Date[5]);
  50. TimeSpan ts = DateTime.Now - dt;
  51. Score += (int)ts.TotalSeconds * TotalBonus;
  52. print("Вы заработали: " + (int)ts.TotalSeconds * TotalBonus + TotalBonus + "$");
  53.  
  54. }
  55.  
  56. public void OnClickButton()
  57. {
  58. Score += ClickScore;
  59. }
  60.  
  61. public void Update()
  62. {
  63. ScoreText.text = Score + "$";
  64. }
  65.  
  66. public void ShowAndHideShopPan()
  67. {
  68. ShopPan.SetActive(!ShopPan.activeSelf);
  69. }
  70. public void ShowAndHideBonusPan()
  71. {
  72. BonusPan.SetActive(!BonusPan.activeSelf);
  73. }
  74.  
  75. public void OnClickBuyLevel()
  76. {
  77. if(Score>= CostInt[0])
  78. {
  79. Score -= CostInt[0];
  80. CostInt[0] *= 2;
  81. ClickScore *= 2;
  82. CostText[0].text = CostInt[0] + "$";
  83. }
  84. }
  85.  
  86. public void OnClickBuyBonusShop()
  87. {
  88. if(Score>= CostInt[1])
  89. {
  90. Score -= CostInt[1];
  91. CostInt[1] *= 2;
  92. CostBonus[0] += 2;
  93. CostText[1].text = CostInt[1] + "$";
  94. }
  95. }
  96.  
  97. IEnumerator BonusShop()
  98. {
  99. while(true)
  100. {
  101. Score +=CostBonus[0];
  102. yield return new WaitForSeconds(1);
  103. }
  104. }
  105.  
  106. #if UNITY_ANDROID && !UNITY_EDITOR
  107.  
  108. public void OnApplicationPause(bool pause)
  109. {
  110. if(pause)
  111. {
  112. sv.Score = Score;
  113. sv.ClickScore = ClickScore;
  114. sv.CostBonus = new int [1];
  115. sv.CostInt = new int[2];
  116.  
  117. for(int i = 0; i < 1; i++)
  118. {
  119. sv.CostBonus[i] = CostBonus [i];
  120. }
  121.  
  122. for(int i = 0; i < 2; i++)
  123. {
  124. sv.CostInt[i] = CostInt [i];
  125. }
  126. sv.Date[0] = DateTime.Now.Year; sv.Date[1] = DateTime.Now.Month; sv.Date[2] = DateTime.Now.Day; sv.Date[3] = DateTime.Now.Hour; sv.Date[4] = DateTime.Now.Minute; sv.Date[5] = DateTime.Now.Second;
  127.  
  128. PlayerPrefs.SetString("SV", JsonUtility.ToJson(sv));
  129. }
  130. }
  131. #else
  132.  
  133. public void OnApplicationQuit()
  134. {
  135. sv.Score = Score;
  136. sv.ClickScore = ClickScore;
  137. sv.CostBonus = new int [1];
  138. sv.CostInt = new int[2];
  139.  
  140. for(int i = 0; i < 1; i++)
  141. {
  142. sv.CostBonus[i] = CostBonus [i];
  143. }
  144.  
  145. for(int i = 0; i < 2; i++)
  146. {
  147. sv.CostInt[i] = CostInt [i];
  148. }
  149. sv.Date[0] = DateTime.Now.Year; sv.Date[1] = DateTime.Now.Month; sv.Date[2] = DateTime.Now.Day; sv.Date[3] = DateTime.Now.Hour; sv.Date[4] = DateTime.Now.Minute; sv.Date[5] = DateTime.Now.Second;
  150. PlayerPrefs.SetString("SV", JsonUtility.ToJson(sv));
  151. }
  152. #endif
  153. }
  154.  
  155. [Serializable]
  156.  
  157. public class Save
  158. {
  159. public int Score;
  160. public int ClickScore;
  161. public int[]CostInt;
  162. public int[]CostBonus;
  163. public int[] Date = new int[6];
  164. }
  165.  
RAW Paste Data