Questions about Script Coroutine c #

1

I made a script next to the coroutine, but rather that it does not work msm not giving error My real intention is to make the button have a delay of up to 10 seconds before making the transition to another canva

Could you give me 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);
   }
}
    
asked by anonymous 03.08.2017 / 01:31

1 answer

2

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

IEnumerator cena()
{
    yield return new WaitForSeconds (10);
    canvas2.SetActive(false);
    canvas3.SetActive(true);
}
    
03.08.2017 / 03:41