Coroutine Problem
Hello, im trying to make a city building game and I want the building to make 10$ every 10 seconds but my coroutine wait 10 seconds and then give me 10$ every 0.1 seconds please help me.
public GameObject Fire;
public float CurrentBuilding;
public float Money = 50;
public float NumberOfFire;
IEnumerator MakingMoney()
{
yield return new WaitForSeconds(10);
Money = Money + 10;
print(Money);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
CurrentBuilding = 1;
}
if (Input.GetMouseButtonDown(1))
{
CurrentBuilding = 0;
}
if ((Input.GetMouseButtonDown(0)) && (CurrentBuilding == 1) && (Money >= 10))
{
NumberOfFire = NumberOfFire + 1;
Money = Money - 10;
Instantiate(Fire, ObjectPos, Quaternion.identity);
print(Money);
}
if (GameObject.Find("Fire(Clone)"))
{
StartCoroutine(MakingMoney());
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make hundrenths of seconds in C#? 1 Answer
how to automatic add numbers in text after the slider finished? 0 Answers
Execute coroutine in Update() 8 Answers
yield ends method 0 Answers
using coroutines 1 Answer