I just started to learn c# in unity. I followed a tutorial, but i wanna add some things.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
pub
In Unity waits are usually done with help of a WaitForSeconds class.
In your case you will have to change OnTriggerEnter
and SetCountText
a bit so that they return IEnumerable
type:
IEnumerable OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ( "Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
yield return SetCountText ();
}
}
IEnumerable SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 1)
{
winText.text = "You Win!";
yield return new WaitForSeconds(5); // Wait for seconds before changing level
Application.LoadLevel(1);
}
}