Questions about Script Coroutine c#

Asked

Viewed 487 times

1

I made a script along with the coroutine, but it kind of doesn’t work without error My real intention is to make the button have a delay of up to 10 seconds before transitioning to another song

could give me a strength?

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

public class canvas2ecanvas3 : MonoBehaviour
{
   public GameObject canvas2,canvas3;
   public void start(){
      StartCoroutine(cena ());
   }
   IEnumerator cena(){
      canvas2.SetActive(false);
      canvas3.SetActive(true);
      yield return new WaitForSeconds (10);
   }
   public void voltar(){
      canvas2.SetActive(true);
      canvas3.SetActive(false);
   }
}
  • Put your code in text, help when copying and pasting to help you ;)

  • I’ll try harder he’s not going

1 answer

2

You need to put the yield before the commands you want to execute. In the current way the code is executing the commands before the yield and then waiting x seconds to do nothing else. Example:

IEnumerator cena()
{
    yield return new WaitForSeconds (10);
    canvas2.SetActive(false);
    canvas3.SetActive(true);
}
  • worst of all is I’ve tried it this way, but I’ll test it again to see

  • Michelly, did the suggestion work? If so, consider marking the answer as you accept it, okay? : ) In addition to rewarding those who helped you, you also help the system work better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.