So I have a function that when I click the button it starts giving me money, I originally placed the money giving code in the update but that gave me money so fast. I want it to have a 5 second delay before giving me more money.
Here is all my code.
Sorry if some of it doesnt make sense, I am going to revise it when I get out the testing stage.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class BuildBuildingTileOne : MonoBehaviour {
public GameObject TileOneBuildButton;
public GameObject TestBuilding;
public Text MoneyText;
public bool TestBuildingActive;
public int Money = 50;
// Use this for initialization
void Start () {
TestBuildingActive = false;
}
// Update is called once per frame
void Update () {
if (TestBuildingActive == false)
{
return;
}
else if (TestBuildingActive == true)
{
MoneyUpdate();
}
MoneyText.text = "Money:" + Money;
}
public void OnMouseDown()
{
TileOneBuildButton.SetActive(true);
}
public void BuildBuilding()
{
TestBuildingActive = true;
TestBuilding.transform.position = new Vector3(5,26,0);
}
public void MoneyUpdate()
{
Money += 1;
StartCoroutine("WaitFiveSeconds");
}
IEnumerator WaitFiveSeconds()
{
yield return new WaitForSeconds(5);
Update();
}
}