Advertisemen
Circle used in the tutorial above :
Making health bar in Unity 5 - radial health bar, 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;
// 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;
}
}
}
using System.Collections;
using UnityEngine.UI;
public class timerTwo : MonoBehaviour {
Image fillImg;
float timeAmt = 10;
float time;
// 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;
}
}
}
Make sure to add "using UnityEngine.UI" otherwise you won't able to use "Image" variable in your script.
Advertisemen
Tidak ada komentar:
Posting Komentar