第一步:添加sprite,设置图片,再给这个sprite添加个sprite的子孩子
第二步:设置CDShade,设置Type模式,Fill Dir默认360就好
第三步:给sprite父类添加脚本,代码如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SetCD : MonoBehaviour {
// Use this for initialization
private UISprite CDsprite;
public float CDTime = 2;
private bool IsCooling = false; //在冷却
void Start () {
CDsprite =transform.Find("CDShade").GetComponent<UISprite>();
}
void SetCDState()
{
if(Input.GetKeyDown(KeyCode.A)&&!IsCooling)
{
IsCooling = true;
CDsprite.fillAmount=1;
}
if (IsCooling)
{
CDsprite.fillAmount -=(1/CDTime)*Time.deltaTime;
if(CDsprite.fillAmount<=0.05f)
{
CDsprite.fillAmount = 0;
IsCooling = false;
}
}
}
// Update is called once per frame
void Update () {
SetCDState();
}
}
运行下看效果如下