DanilaI

GameEarth

Aug 9th, 2022
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Game : MonoBehaviour
  7. {
  8.  
  9.     public Text moneyText;
  10.     public Text[] CostText;
  11.  
  12.     public int money;
  13.     public int moneyPerClick = 1;
  14.     public int addMoney;
  15.     public int farmS;
  16.     public int level;
  17.     private int clickNum;
  18.     public int[] CostInt;
  19.     //public int[] clikers = new int[] { moneyPerClick, };
  20.  
  21.     public bool isFirst;
  22.     public bool isIdleFarm;
  23.  
  24.     public GameObject clickParent, clicktextPrefab;
  25.     public GameObject[] points;
  26.     private ClickObject[] clickTextPool = new ClickObject[10];
  27.  
  28.  
  29.  
  30.  
  31.     void Start()
  32.     {
  33.         money = PlayerPrefs.GetInt("money");
  34.         addMoney = PlayerPrefs.GetInt("addMoney");
  35.         farmS = PlayerPrefs.GetInt("farmS");
  36.         moneyPerClick = PlayerPrefs.GetInt("moneyPerClick");
  37.  
  38.         bool isFirst = PlayerPrefs.GetInt("isFirst") == 1 ? true : false;
  39.         bool isIdleFarm = PlayerPrefs.GetInt("isIdleFarm") == 1 ? true : false;
  40.         //bool IdleFarmButton = PlayerPrefs.GetInt("IdleFarmButton") == 1 ? true : false;
  41.  
  42.         for (int i = 0; i < clickTextPool.Length; i++)
  43.         {
  44.             clickTextPool[i] = Instantiate(clicktextPrefab, clickParent.transform).GetComponent<ClickObject>();
  45.         }
  46.  
  47.  
  48.         if (isIdleFarm == true)
  49.         {
  50.             StartCoroutine(IdleFarm());
  51.         }
  52.         //if (isFirst == false)
  53.         //{
  54.             //IdleFarmButton.interactable = false;
  55.         //}
  56.     }
  57.  
  58.     void Update()
  59.     {
  60.         money = PlayerPrefs.GetInt("money");
  61.         //moneyText.text = money.ToString();
  62.         moneyText.text = FormatNumbers.formatNumber(money);
  63.     }
  64.  
  65.     public void ObjBuy()
  66.     {
  67.         if (money >= CostInt[0])
  68.         {
  69.             money -= CostInt[0];
  70.             CostInt[0] += (int) Mathf.Round(CostInt[0] * 30 / 100);
  71.             addMoney *= (int)Mathf.Round(CostInt[0] * 20 / 100);
  72.             CostText[0].text = CostInt[0].ToString();
  73.  
  74.             PlayerPrefs.SetInt("addMoney", addMoney);
  75.             PlayerPrefs.SetInt("money", money);
  76.         }
  77.     }
  78.  
  79.  
  80.     public void addBuy()
  81.     {
  82.         if (money >= 20)
  83.         {
  84.             money -= 20;
  85.             PlayerPrefs.SetInt("money", money);
  86.             addMoney += 1;
  87.             PlayerPrefs.SetInt("addMoney", addMoney);
  88.         }
  89.     }
  90.  
  91.     public void Clik()
  92.     {
  93.         money += moneyPerClick;
  94.         PlayerPrefs.SetInt("money", money);
  95.         ///clickTextPool[clickNum].StartMotion();
  96.         clickNum = clickNum == clickTextPool.Length - 1 ? 0 : clickNum + 1;
  97.         Debug.Log("Earth");
  98.     }
  99.  
  100.     public void BuyIdleFarm()
  101.     {
  102.         if (money >= 20)
  103.         {
  104.             money -= 20;
  105.             addMoney += 1;
  106.             farmS += 1;
  107.  
  108.             PlayerPrefs.SetInt("money", money);
  109.             PlayerPrefs.SetInt("addMoney", addMoney);
  110.             PlayerPrefs.SetInt("farmS", farmS);
  111.             StartCoroutine(IdleFarm());
  112.             isIdleFarm = true;
  113.             PlayerPrefs.SetInt("isIdleFarm", (true ? 1 : 0));
  114.             IdleFarmButton.interactable = false;
  115.             isFirst = false;
  116.             PlayerPrefs.SetInt("isFirst", (false ? 1 : 0));
  117.             //PlayerPrefs.SetInt("IdleFarmButton", (false ? 1 : 0));
  118.         }
  119.     }
  120.  
  121.     IEnumerator IdleFarm()
  122.     {
  123.         yield return new WaitForSeconds(farmS);
  124.         money += addMoney;
  125.         Debug.Log(money);
  126.         PlayerPrefs.SetInt("money", money);
  127.         //clickTextPool[clickNum].StartMotionIdle();
  128.        //clickNum = clickNum == clickTextPool.Length - 1 ? 0 : clickNum + 1;
  129.         StartCoroutine(IdleFarm());
  130.     }
  131. }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment