I want to give the game a time limit to be completed, and if the player doesnt get all the cubes in that window of time, the game ends and its shows a “You Lose” text.
My code looks like this so far:
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
public class PlayerControler : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
public Text timerText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody> ();
count = 0;
SetCountText ();
winText.text = "";
}
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 >= 14)
{
winText.text = "You Win!";
}
}
}