diff --git a/Computer.cs b/Computer.cs new file mode 100644 index 0000000..fc3c150 --- /dev/null +++ b/Computer.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; + +public class Computer : MonoBehaviour +{ + private GameManager gameManager; + public TextMeshPro iterationText; + + // Start is called before the first frame update + void Start() + { + gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent(); + } + + // Update is called once per frame + void Update() + { + if (gameManager.timeIteration>=3) + iterationText.text = gameManager.timeIteration.ToString(); + } +} diff --git a/FadeManager.cs b/FadeManager.cs index b166817..bc9c09b 100644 --- a/FadeManager.cs +++ b/FadeManager.cs @@ -23,6 +23,7 @@ public IEnumerator Fade(Color color, Image image, GameObject room) fading = true; yield return FadeIn(color, image); gameManager.Teleport(room); + if (gameManager.timeRestart) gameManager.RewindTime(); yield return new WaitForSeconds(0.25f); yield return FadeOut(image); diff --git a/GameManager.cs b/GameManager.cs index 3925f4d..aefbf06 100644 --- a/GameManager.cs +++ b/GameManager.cs @@ -15,12 +15,13 @@ public class GameManager : MonoBehaviour private Player player; public GameObject teleportDes; public bool isPaused = false; + public Image fadeImage; + public FadeManager fadeManager; + public bool timeRestart = false; private Image fadeImage; private FadeManager fadeManager; - - - private float timeIteration; + [HideInInspector] public float timeIteration; private float timeLeft = TIMELIMIT; public TextMeshProUGUI timerText; // Start is called before the first frame update @@ -57,6 +58,7 @@ IEnumerator LoseTime() { if (timeLeft <= 0.0f) { + timeRestart = true; timerText.enabled =false; yield return timerEnded(); timerText.enabled=true; @@ -72,20 +74,19 @@ IEnumerator LoseTime() } IEnumerator timerEnded() { - timeIteration++; timeLeft = TIMELIMIT; Debug.Log("REWIND TIME\n Time iteration: "+timeIteration); fadeImage.color = Color.clear; yield return GameObject.FindGameObjectWithTag("FadeManager").GetComponent().Fade(Color.blue, fadeImage, teleportDes); - RewindTime(); } public void RewindTime() { + timeIteration++; player.SetDefault(); - + timeRestart = false; }