I’m trying to add a timer to the rolling ball tutorial to make it track how long it takes you. i got the timer to run but i’m trying to make the timer stop when “You Win!” appears. Help would be greatly appreciated. here’s the code i have for it if that helps.
also i’m a beginner to C#.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text timerText;
public float startTime;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
setCountText ();
winText.text = "";
startTime = Time.time;
}
void Update ()
{
float t = Time.time - startTime;
string minutes = ((int)t / 60).ToString ();
string seconds = (t % 60).ToString ("f2");
timerText.text = minutes + ":" + seconds;
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ("Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
setCountText ();
}
}
void setCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}