Wait isn't working?

I have a coroutine that is supposed to change the variable AmmoCount by 1 and then wait a bit to stop it from changing to quickly but it doesn’t seem to be waiting.

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

public class AmmoDisplay : MonoBehaviour
{

    public GameObject ammoTextUI;
    public int AmmoCount;
    // Update is called once per frame
    private void Start()
    {
        AmmoCount = 20;
    }



    void Update()
    {
        if (AmmoCount > 10)
        {
            ammoTextUI.GetComponent<Text>().text = "0" + AmmoCount;
        }
        if (AmmoCount > 0 & AmmoCount < 10)
        {
            ammoTextUI.GetComponent<Text>().text = "00" + AmmoCount;
        }
        if (Input.GetMouseButton(0) && AmmoCount > 0)
        {

            StartCoroutine(Wait());

        }
        if (AmmoCount == 0)
        {
            AmmoCount = 20;
        }
    }
    IEnumerator Wait()
    {
        AmmoCount--;
        yield return new WaitForSeconds(10f);
    }
}

Plz Help!

        yield return new WaitForSeconds(10f);
        AmmoCount--;

:wink:

Now it just bugs out and stops.

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

public class AmmoDisplay : MonoBehaviour
{

    public GameObject ammoTextUI;
    public int AmmoCount;
    // Update is called once per frame
    private void Start()
    {
        AmmoCount = 20;
    }



    void Update()
    {
        if (AmmoCount > 10)
        {
            ammoTextUI.GetComponent<Text>().text = "0" + AmmoCount;
        }
        if (AmmoCount > 0 & AmmoCount < 10)
        {
            ammoTextUI.GetComponent<Text>().text = "00" + AmmoCount;
        }
        if (Input.GetMouseButton(0) && AmmoCount > 0)
        {

            StartCoroutine(Wait());

        }
        if (AmmoCount == 0)
        {
            AmmoCount = 20;
        }
    }
    IEnumerator Wait()
    {
        yield return new WaitForSeconds(0.5f);
        AmmoCount--;
    }
}

Well, you should never try to run a “Coroutine” in any “Loop” method.

you are Starting X Coroutines at the same time.