1. 程式人生 > >UGUI實現技能cd效果

UGUI實現技能cd效果

、using UnityEngine;
using System.Collections;
//匯入這個類  (自動匯入外掛)
using UnityEngine.UI;


public class SkillItem : MonoBehaviour {


// Use this for initialization
//冷卻cd時間
public float cdTime = 2;
private bool isStartTimer;
private float time;
private Image filledImage;
public KeyCode myKey;
void Start () {
filledImage = transform.Find ("mask").GetComponent<Image> ();

}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown (myKey))
{
isStartTimer = true;
}
if (isStartTimer)
{
time += Time.deltaTime;
filledImage.fillAmount = (cdTime - time) / time;
if (time >= cdTime)
{
filledImage.fillAmount = 0;
time = 0;
isStartTimer = false;
}
}
}


public void onClick()
{
isStartTimer = true;
}

}

 mask這裡設定為Filled