Hi, I’m new to Unity and I’m still learnig.
I made a little level where a ball has to reach the end before the timer reach the 0.
When the player reach the end a win screen appear and show you the score you have made and your time to complete the level.
What I want to know is: How can I stop the time in the winscreen after the player reached the end?
If they can be usefull down here there are the stopwatch script and the end trigger script:
Stopwatch:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class stopwatch : MonoBehaviour
{
public float timeStart = 0;
public TextMeshProUGUI textBox;
private bool isGameStarted = false;
private bool gameEnded = false;
// Start is called before the first frame update
void Start()
{
textBox.text = timeStart.ToString();
}
// Update is called once per frame
void Update()
{
timeStart += Time.deltaTime;
Debug.Log(timeStart);
textBox.text = Mathf.Round(timeStart).ToString();
if (timeStart < 0)
{
timeStart = 0;
isGameStarted = false;
gameEnded = true;
}
if (gameEnded == true)
{
FindObjectOfType<Gamemanager>().EndGame();
}
}
}
Endtrigger:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Endtrigger : MonoBehaviour
{
public Gamemanager Gamemanager;
public GameObject Scermatadicountdown;
private void OnTriggerEnter(Collider other)
{
Scermatadicountdown.GetComponent<countdown>().enabled = false;
Gamemanager.Completelevel();
}
}