Skip to content

Instantly share code, notes, and snippets.

@ealbinu
Created April 23, 2013 05:43
Show Gist options
  • Select an option

  • Save ealbinu/5441081 to your computer and use it in GitHub Desktop.

Select an option

Save ealbinu/5441081 to your computer and use it in GitHub Desktop.
Script para Unity que ejecuta una resta de 1 cada segundo
#pragma strict
var valorInicial : int = 5;
var GUITextVisualizador : GUIText;
function Start () {
// Llamada a función contadora
CountDown();
}
function CountDown(){
if(valorInicial>0){ // Si valorInicial es mayor a 0
GUITextVisualizador.text = valorInicial.ToString(); // Imprimir valorInicial en variable GUI como String
yield WaitForSeconds(1); // Esperar 1 segundo antes de ejecutar lo que esta debajo
valorInicial--; // Restar 1 a valorInicial
Reiniciar(); // Función Loop
} else { // Si ya no es mayor a 0
GUITextVisualizador.text = 'Conteo finalizado'; // Al terminar el conteo
}
}
function Reiniciar(){
CountDown(); // Ejecutar de nuevo la función contadora
}
@betotulkas
Copy link

betotulkas commented Jun 20, 2018

    public  float Time_GameOver ;
     public bool x =true;
     void Start () {
            bool x =true;
	StartCoroutine(Example());
}
IEnumerator Example()
{         while(x)  {
	Time_GameOver -= 1;
	yield return new WaitForSeconds(1);
               }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment