Add an value to a variable after 2 seconds

Hi
i’m trying to add every 2 seconds an value to a variable, but it adds the value every Frame how can i make it work.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class playerController : MonoBehaviour {

    public Text money;
    public Text playerMoney;
    public bool test;

    public static int actualPlayerMoney;
     public static int actualMoney;

	// Use this for initialization
	void Start () {

        test = true;
        actualMoney = 0;
        actualPlayerMoney = 0;
        playerMoney.text = "0";
        money.text = "Money: " + actualMoney;

        
        

    }
	
	// Update is called once per frame
	void Update () {

        actualMoney++;
        SetText(money, "Money: ", actualMoney);
        StartCoroutine(AddMoney());
        SetText(playerMoney, "", actualPlayerMoney);

        if (actualPlayerMoney == 50) test = false;



    }

    void SetText(Text text, string content, int count)
    {
        text.text = content + count.ToString();

    }

    IEnumerator AddMoney()
    {
        while (true)
        {
            yield return new WaitForSeconds(5);
            Debug.Log("Sending");
            yield return new WaitForSeconds(5);

        }
    }
}

From what I can see, the reason this is happening is because you are calling the “money++” just inside the update. you should be doing that inside your coroutine

try this

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class playerController : MonoBehaviour {

 public Text money;
 public Text playerMoney;
 public bool test;

 public static int actualPlayerMoney;
  public static int actualMoney;

 // Use this for initialization
 void Start () {

     test = true;
     actualMoney = 0;
     actualPlayerMoney = 0;
     playerMoney.text = "0";
     money.text = "Money: " + actualMoney;

     
     

 }
 
 // Update is called once per frame
 void Update () {

     //actualMoney++; // this is called once per frame so money is added once every frame
     SetText(money, "Money: ", actualMoney);
     StartCoroutine(AddMoney());
     SetText(playerMoney, "", actualPlayerMoney);

     if (actualPlayerMoney == 50) test = false;



 }

 void SetText(Text text, string content, int count)
 {
     text.text = content + count.ToString();

 }

 IEnumerator AddMoney()
 {
     while (true)
     {
         //yield return new WaitForSeconds(5);// this will pause for 5 seconds
        actualMoney++;
        Debug.Log("Sending");
         yield return new WaitForSeconds(2);

     }
 }

}

Hope this helps