Help needed with Update and Wait function.

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();
    }
}

Replace MoneyUpdate(); with Invoke(“MoneyUpdate”, 5); and delete the coroutine completely.

It worked for the first delay but then it went back to every frame giving me money. I hope I didn’t misunderstand anything,
I did leave this in, was I supposed to delete it?

IEnumerator WaitFiveSeconds()
    {
        yield return new WaitForSeconds(5);
        Update();
    }

I’m guessing it’s because TestBuildingActive stays true, so it keeps invoking every frame.

Do you have any Idea how I would fix that?

Watch some tutorials…

Any way…

if (TestBuildingActive == true)
{
    Invoke("MoneyUpdate",5);
    TestBuildingActive = false;
}

Update is a Message in MonoBehaviour and it’s automatic called every frame

Try these

float currentTime = .0f;
float timeAfterAddMoney = 5.0f;

void Update()
{
   if(Input.getMouseButtonDown(0))
   {
       addMoney();
       currentTime = time.Time + timeAfterAddMoney;//Works like timer
   }

   if(Input.getMouseButton(0))
   {
        if(currentTime < time.Time)
        {
             addMoney();
             currentTime = time.Time + timeAfterAddMoney;
        }
   }
}