Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class Timmer : MonoBehaviour {
  6.  
  7. public Text Tempo;
  8. public float tiempo = 0.0f;
  9.  
  10.  
  11.  
  12. // Update is called once per frame
  13. void Update () {
  14. tiempo -= Time.deltaTime;
  15. Tempo.text = "Tiempo:" + " " + tiempo.ToString ("f0");
  16.  
  17. }
  18. }
  19.  
  20. public class Timmer : MonoBehaviour
  21. {
  22. public Text Tempo;
  23. public float Tiempo = 0.0f;
  24. public bool DebeAumentar = false;
  25.  
  26. void Update()
  27. {
  28. if (DebeAumentar)
  29. Tiempo += Time.deltaTime;
  30. // Primero se comprueba que sea falso el tener que aumentar.
  31. else
  32. {
  33. if (Tiempo <= 0.0f) // Comprueba si es menor o igual a cero.
  34. { DebeAumentar = true; } // Para volver true a este.
  35. else
  36. { Tiempo -= Time.deltaTime; } // De lo contrario, sigue bajando.
  37. }
  38. if (Tiempo <= 30.0f)
  39. { Tempo.color = Color.Red; } // Comprueba para cambiar el color del text.
  40. else { Tempo.color = Color.Green; } // Vuelve a verde cuando aumente...
  41.  
  42. Tempo.text = "Tiempo:" + " " + Tiempo.ToString ("f0");
  43. }
  44. }
  45.  
  46. public class Timmer : MonoBehaviour
  47. {
  48. public Text Tempo;
  49. public float Tiempo = 0.0f;
  50. public bool DebeAumentar = false;
  51.  
  52. void Update()
  53. {
  54. // Se comprueba si debe aumentar el valor primero...
  55. DebeAumentar = (Tiempo <= 0.0f) ? true : false;
  56.  
  57. // Luego se efectua el aumento.
  58. if (DebeAumentar) Tiempo += Time.deltaTime;
  59. else Tiempo -= Time.deltaTime;
  60.  
  61. // Se asigna el color dependiendo del tiempo restante.
  62. Tempo.color = (Tiempo <= 30.0f) ? Color.Red : Color.Green;
  63.  
  64. Tempo.text = "Tiempo:" + " " + Tiempo.ToString ("f0");
  65. }
  66. }
  67.  
  68. Var = (Condición) ? (Si cumple la condición, se asigna este valor) : (De lo contrario, este);
  69.  
  70. public class Countdown: MonoBehaviour {
  71. public int duration = 60;
  72. public int timeRemaining;
  73. public bool isCountingDown = false;
  74. public void Begin()
  75. {
  76. if (!isCountingDown) {
  77. isCountingDown = true;
  78. timeRemaining = duration;
  79. Invoke ( "_tick", 1f );
  80. }
  81. }
  82.  
  83. private _tick() {
  84. timeRemaining--;
  85. if(timeRemaining > 0) {
  86. Invoke ( "_tick", 1f );
  87. } else {
  88. isCountingDown = false;
  89. }
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement