Делаю кликер, и тут дошёл до сохранений. Но я вообще не бум-бум в данной теме, так что подскажите кто может. Код: using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Collections; using System;
public class Game : MonoBehaviour { public Text scoreText; private int score = 0; private int bonus = 1; private int workersCount,workersBonus = 1; public Button[] shopBttns; public float[] bonusTime;
[Header("Магазин")] public int[] shopCosts; public int[] shopBonuses; public GameObject shopPan;
Код:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
public class Game : MonoBehaviour
{
public Text scoreText;
private int score = 0;
private int bonus = 1;
private int workersCount,workersBonus = 1;
public Button[] shopBttns;
public float[] bonusTime;
[Header("Магазин")]
public int[] shopCosts;
public int[] shopBonuses;
public GameObject shopPan;
private void Start()
{
StartCoroutine(BonusPerSec());
}
private void Update()
{
scoreText.text = score + " печенек";
}
public void shopPan_ShowAndHide()
{
shopPan.SetActive(!shopPan.activeSelf);
}
public void shopBttn_addBonus(int index)
{
if (score >= shopCosts[index])
{
bonus *= shopBonuses[index];
score -= shopCosts[index];
}
else
{
Debug.Log("no");
}
}
public void HireFWorker(int index)
{
if (score >= shopCosts[index])
{
workersCount++;
score -= shopCosts[index];
}
else
{
Debug.Log("no");
}
}
public void startBonusTimer(int index)
{
StartCoroutine(bonusTimer(bonusTime[index], index));
}
IEnumerator BonusPerSec()
{
while (true)
{
score += (workersCount * workersBonus);
yield return new WaitForSeconds(1);
}
}
IEnumerator bonusTimer(float time, int index)
{
shopBttns[index].interactable = false;
if (index == 0)
{
workersBonus *= 2;
yield return new WaitForSeconds(time);
workersBonus /= 2;
}
shopBttns[index].interactable = true;
}
public void OnClick()
{
score += bonus;
scoreText.text = score + " печенек";
}
}