Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

305
Visualizações
Wait for some seconds before it executes further code in UNITY?

So i have tried doing this :

void Update()
    {
        if (isWalkingTowards)
        {
            if (Vector3.Distance(character.transform.position,this.transform.position)<0.7)
            {
                **StartCoroutine(Example());**
                Instantiate(character, new Vector3(-6, 0, -1), Quaternion.identity);
                Destroy(character);

            }
        }
    }
    **IEnumerator Example()
    {
        yield return new WaitForSecondsRealtime(5);
        Debug.Log("This function should be read before it is instantiated or destroyed");
    }**

But it just instantiates and destroys object and after that it shows me that message!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I should have done this:

void Update()
    {
        if (isWalkingTowards)
        {
            if (Vector3.Distance(character.transform.position,this.transform.position)<0.7)
            {
                **StartCoroutine(Example());**
            }
        }
    }
    **IEnumerator Example()
    {
        yield return new WaitForSecondsRealtime(5);
        Debug.Log("This function should be read before it is instantiated or destroyed");
        Instantiate(character, new Vector3(-6, 0, -1), Quaternion.identity);
        Destroy(character);
    }**
over 4 years ago · Santiago Trujillo Relatório

0

Here is a super helpful link on a bunch of ways to wait in unity: How to make the script wait/sleep in a simple way in unity

Also, I think the issue you're currently running into is that the code won't wait for StartCoroutine(Exmaple()) to finish. You have to put the code you want to execute before and after in Example.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda