Created
January 15, 2018 09:26
-
-
Save ryo-ma/c5c14bf2f4eff6a16b9a819c9c84e7eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| using System; | |
| public class LimitTimer : MonoBehaviour | |
| { | |
| public Text timerText | |
| public int minute; | |
| public float seconds; | |
| private float totalTime; | |
| private float oldSeconds; | |
| private float startTime; | |
| void Start() | |
| { | |
| this.totalTime = this.minute * 60 + this.seconds; | |
| this.oldSeconds = 0f; | |
| this.startTime = Time.realtimeSinceStartup; | |
| } | |
| void Update() | |
| { | |
| float remainTime = this.totalTime - (Time.realtimeSinceStartup - this.startTime); | |
| if (remainTime <= 0f) | |
| { | |
| return; | |
| } | |
| float remainMinute = (int)remainTime/ 60; | |
| float remainSeconds = remainTime - remainMinute * 60; | |
| if ((int)remainSeconds != (int)oldSeconds) | |
| { | |
| this.timerText.text = String.Format("limit {0}:{1}", remainMinute.ToString("00"), ((int)remainSeconds).ToString("00")); | |
| } | |
| this.oldSeconds = remainSeconds; | |
| if (remainTime <= 0f) | |
| { | |
| Debug.Log("time finished"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment