Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Yield wait for seconds en c#

Iniciado por , Julio 21, 2015, 03:05:09 PM

Tema anterior - Siguiente tema
Quiero que espere unos segundos despues de que sea destruido y salga el game over para entonces llevarlo a la portada. Pero no lo hace aunque imprime el texto pero no se va a la portada.Gracias!!
public class vidadron : MonoBehaviour {

public Slider healthBarSlider;  //reference for slider
public Text gameOverText;   //reference for text
//private bool isGameOver = false; //flag to see if game is over
// Use this for initialization
public Rigidbody explosion;


void Start () { gameOverText.enabled = false; //disable GameOver text on start

}


void Update () {

}


void OnTriggerEnter(Collider other)
{
   //if player triggers fire object and health is greater than 0
   if(other.gameObject.tag == "Enemigo" && healthBarSlider.value>0)
   {
      healthBarSlider.value -=.30f;  //reduce health
   }
   if (other.gameObject.tag == "Enemigo" && healthBarSlider.value <= 0)
   {
      //isGameOver = true;    //set game over to true
      gameOverText.enabled = true; //enable GameOver text
   }
   if(other.gameObject.tag == "Borde" && healthBarSlider.value>0)
   {
      
      Destroy (gameObject) ;  
      Instantiate (explosion, transform.position, transform.rotation);
      gameOverText.enabled = true; //enable GameOver text
      StartCoroutine("Waitplease");

   }
   
}
IEnumerator Waitplease()
{
       print("Print something");
      yield return new WaitForSeconds (1);
      Application.LoadLevel (0);
   }
}
 

Julio 21, 2015, 03:18:51 PM #1 Ultima modificación: Enero 01, 1970, 01:00:00 AM por Antonio
Si imprime el texto en su momento, es que la función debe estar bien.

Si lo único que falla es el cargar nivel, ¿puede ser que no tengas compilado el nivel 0? (En File, cuando le das a Build Settings, está metido el nivel del menú principal? ¿está puesto en el puesto 0?).

Julio 21, 2015, 04:24:36 PM #2 Ultima modificación: Julio 22, 2015, 02:16:37 PM por Aunel
[Solucionado en parte] Le he puesto un script a parte en los bordes y ya esta.Ahora faltaria poner un temporizador de 3 seg cuando se choque con otros enemigos.Alguien me podria facilitar un temporizador que no vaya en update en c#??? 

Etiquetas: