Why is the coroutine not working?

Hi, im doing the next code and I have a problem with the coroutine. It is not working, when I press the button to start the function “PlantarComidaUno”, it don’t wait the 5 seconds and does it inmediatly. What is wrong?

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

public class FuncionCultivo : MonoBehaviour {
    // Los recursos del jugador
    public int comidaArcas;

    // Las plantas que creceran
    [SerializeField] GameObject plantaJoven;
    [SerializeField] GameObject plantaCrecida;

    // Tiempo de crecimiento de cada planta
    // public float tiempoPlantaUno;

    // Variables temporales
    private int cultivoCreciendo;
    private int cultivoMaduro;


    void Update () {
        // Recursos del jugador
        comidaArcas = PlayerPrefs.GetInt ("recursoComidaGlobal");
    }

    // El jugador gasta comida para plantar
    public void PlantarComidaUno() {
        if ((comidaArcas >= 100) && (cultivoCreciendo == 0) && (cultivoMaduro == 0)) {
            PlayerPrefs.SetInt ("recursoComidaGlobal", comidaArcas - 100);
            cultivoCreciendo = 1;
            plantaJoven.SetActive(true);
            Debug.Log ("Plantando...");
            StartCoroutine (Wait(5.0f));
            Debug.Log ("PLANTADO");
            cultivoCreciendo = 0;
            cultivoMaduro = 1;
            plantaCrecida.SetActive(true);

        }
    }

    // El jugador recoge la comida madura
    public void RecolectarComidaUno() {
        if (cultivoMaduro == 1) {
            cultivoMaduro = 0;
            plantaJoven.SetActive(false);
            plantaCrecida.SetActive(false);
            PlayerPrefs.SetInt ("recursoComidaGlobal", comidaArcas + 200);
        }
    }


    IEnumerator Wait(float tempo) {
        while (true) {
            yield return new WaitForSeconds (tempo);
        }
    }
       
       
}

What do you expect it to do? Do you think it is going to halt the execution of code in your PlantarComidaUno method?

Also why do you have a while statement in it?

A coroutine only pauses for code that is inside of its own routine. Update() is not a coroutine, it will not pause for what is happening in a routine, that would freeze your whole game if it did.

What you would need to do is turn PlantarComidaUno() into an IEnumerator as well and launch it. And inside that you need to do yield return StartCoroutine(Wait(0.5f)); instead, which will make the processing in that Coroutine pause until the launched “Wait()” routine fully finishes.

But, since you have “while(true)” in that Wait() routine, it will never finish… Remove the While() part as well. But if all you want to do is wait, then don’t even use that Wait() method. Just put yield return new WaitForSeconds(0.5f); there instead.