使用startCoroutine制定倒计时
using UnityEngine;
using System.Collections; public class TimerCoroutine : MonoBehaviour
{
public int second;
// Use this for initialization
void Start ()
{
StartCoroutine("timeSecond");
} void OnGUI()
{
GUI.Label(new Rect(100, 100, 100, 100), second.ToString());
} IEnumerator timeSecond()
{
while(second>0)
{
yield return new WaitForSeconds(1f);
second -= 1; Debug.Log("second" + second);
}
} }