Watch Video Tutorial On My Channel
Assets:
White Dotted image is here |
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Loading : MonoBehaviour {
public Image loading;
public Text timeText;
public int minutes;
public int sec;
int totalSeconds = 0;
int TOTAL_SECONDS = 0;
float fillamount;
void Start ()
{
timeText.text = minutes + " : " + sec;
if (minutes > 0)
totalSeconds += minutes * 60;
if (sec > 0)
totalSeconds += sec;
TOTAL_SECONDS = totalSeconds;
StartCoroutine (second ());
}
void Update ()
{
if (sec == 0 && minutes == 0) {
timeText.text = "Time's Up!";
StopCoroutine (second ());
}
}
IEnumerator second()
{
yield return new WaitForSeconds (1f);
if(sec > 0)
sec--;
if (sec == 0 && minutes != 0) {
sec = 60;
minutes--;
}
timeText.text = minutes + " : " + sec;
fillLoading ();
StartCoroutine (second ());
}
void fillLoading()
{
totalSeconds--;
float fill = (float)totalSeconds/TOTAL_SECONDS;
loading.fillAmount = fill;
}
}
Thank you
ReplyDeletepublic static int minut=0;
ReplyDeletepublic static int seconds=60;
Start(){
StartCoroutine(TimeClock());
}
public IEnumerator TimeClock() {
do
{
if (seconds > 0)
{
yield return new WaitForSeconds(1f);
seconds = seconds - 1;
//total time divide here....
StopWatchImage.GetComponent().fillAmount = StopWatchImage.GetComponent().fillAmount-(StopWatchImage.GetComponent().fillAmount / 60);
Debug.Log(seconds);
if (seconds < 10)
{
UI_seconds.text = "0"+seconds.ToString();
}
else
{
UI_seconds.text = seconds.ToString();
}
if (minut > 0 && seconds < 1)
{
minut = minut - 1;
seconds = 60;
Debug.Log(minut);
if (minut < 10)
{
UI_minute.text = "0" + minut.ToString();
}
else {
UI_minute.text = minut.ToString();
}
}
else if(minut == 0 && seconds < 1)
{
Debug.Log("Minute : " + minut);
Debug.Log("Time up");
break;
}
}
else
{
Debug.Log("Time up");
break;
}
} while (seconds>0);
}