Работа с button. Unity
Всем привет. У меня есть проблема, которую я не могу уже решить целую неделю. Я пытался сделать так, чтобы при нажатие button, изменялись параметры в yield return new WaitForSeconds(1);. И чтобы нажатие стоило 100 money. Пример: Пользователь хочет нажать на кнопку, но без 100 moneyон не cможет нажать на кнопку, ждет пока у него накопится 100 money и нажимает. После нажатие у пользователя уменьшается 100 money и изменяется в IEnumerator CountPoints() число в yield return new WaitForSeconds(1);, то есть на yield return new WaitForSeconds(0.8f);.
Вот скрипт:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Game : MonoBehaviour
{
public Text sub;
public int score;
public Text money;
public int score1;
public Text top;
public int score2;
void Start()
{
StartCoroutine(CountPoints());
StartCoroutine(CountPoints1());
StartCoroutine(CountPoints2());
}
IEnumerator CountPoints()
{
while (score < 10000)
{
sub.text = score.ToString();
score++;
yield return new WaitForSeconds(1);
}
}
IEnumerator CountPoints1()
{
while (score1 < 10000)
{
money.text = score1.ToString();
score1++;
yield return new WaitForSeconds(0.5f);
}
}
IEnumerator CountPoints2()
{
while (score2 > 0)
{
top.text = score2.ToString();
score2--;
yield return new WaitForSeconds(5);
}
}
}
Еще у меня есть просьба, можете объяснить, каким вы способом сделали это. Буду очень благодарен ??.