Hi, I am completely new to Unity and have been working on it at school. Of course, my start has been the “Roll a Ball” thing, and I’ve tried looking about to make some changes. I was wanting to change (or really just add in) the duration of the “winText” that pops up directing the player to move ahead. At the moment it just stays there permanently, but I’d like it to disappear after 5 seconds.
If someone had any idea how to do this it would be greatly appreciated.
This is what I had in total:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
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 >= 8)
{
winText.text = "Great. Now hit the blue wall.";
}
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "North Wall" && count >= 8)
{
Destroy (col.gameObject);
}
}
}