So, I am very new to Unity and C# Scripting, I really don’t want to have to get into JavaScript If I have to, so if the answers below can please be using C# That would be fantastic.
I’m trying to make it so my UI Text of “You have completed your task” (WinText)to fade away after a set amount of time, Or just deactivate after some time, Preferably 3-5 seconds. I’m not sure how to do this, I’ve checked into Coroutines but I kind of understand it, but have no idea how to put it into my script. Take a look and tell me if you have any ideas! Thanks!
[My code Is set to Only display the UI Text as soon as Count reaches 100]
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Player : MonoBehaviour {
private int count;
public Text countText;
public Text winText;
bool collected = false;
// Use this for initialization
void Start () {
count = 0;
SetCountText ();
winText.text = “”;
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter ( Collider other ) {
if (other.gameObject.CompareTag (“Pick Up”)) {
other.gameObject.SetActive(false);
count = count + 1;
SetCountText ();
}
if (count >= 100 && collected == false) {
GameObject gem = (GameObject)Instantiate(Resources.Load(“Gem”));
collected = true;
}
}
void SetCountText(){
countText.text = ": " + count.ToString ();
if (count >= 100) {
winText.text = “You have Completed your Task”;
}
}
}