Advertisemen
Adding timer to progress bar in Unity 5, C# script used in the tutorial above :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class timerTwo : MonoBehaviour {
Image fillImg;
float timeAmt = 10;
float time;
public Text timeText;
// Use this for initialization
void Start () {
fillImg = this.GetComponent<Image>();
time = timeAmt;
}
// Update is called once per frame
void Update () {
if(time > 0){
time -= Time.deltaTime;
fillImg.fillAmount = time / timeAmt;
timeText.text = "Time : "+time.ToString("F");
}
}
}
using System.Collections;
using UnityEngine.UI;
public class timerTwo : MonoBehaviour {
Image fillImg;
float timeAmt = 10;
float time;
public Text timeText;
// Use this for initialization
void Start () {
fillImg = this.GetComponent<Image>();
time = timeAmt;
}
// Update is called once per frame
void Update () {
if(time > 0){
time -= Time.deltaTime;
fillImg.fillAmount = time / timeAmt;
timeText.text = "Time : "+time.ToString("F");
}
}
}
Make sure to add "using UnityEngine.UI" otherwise you won't able to use "Image", "Text" variables in your script.
Advertisemen
Tidak ada komentar:
Posting Komentar