using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TimerStartEnd : MonoBehaviour { public bool bStart = false; public float fStartTime; public float fDurationTime; public Text txtTimer; public int iCount; // Use this for initialization void Start () { bStart = false; txtTimer.text = "0"; iCount = 0; } // Update is called once per frame void Update () { int iSec; if (bStart) { fDurationTime = Time.time - fStartTime; iSec = Mathf.FloorToInt(fDurationTime); txtTimer.text = iSec.ToString(); } } void OnTriggerEnter(Collider other) { if (other.tag == "CheckPoint1") { if(iCount==0) { bStart = true; fStartTime = Time.time; } else if(iCount==2) { bStart = false; } iCount++; } if (other.tag == "CheckPoint2") { iCount++; } } }