1. 建立两个相同的技能CD图片,
要将里面的图片的color 设置的比外面的颜色深一点 这样效果比较好!
2 .修改 Image 的 Image Type
3.编写脚本
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ReleaseSkill : MonoBehaviour {
Image image;
public float coldTime = 10f;
float time;
// Use this for initialization
void Start () {
//获取image组件 需要加UnityEngine.UI命名空间
image = this.GetComponent<Image>();
}
// Update is called once per frame
void Update()
{
//方案一
//if (Input.GetKeyDown(KeyCode.Q))
//{
// image.fillAmount = 0;
//}
//if (image.fillAmount < 1)
//{
// time += Time.deltaTime;
// image.fillAmount = time / coldTime;
//}
//else
//{
// time = 0;
//}
//方案二
if (Input.GetKeyDown(KeyCode.W) && image.fillAmount >= 1)
{
image.fillAmount = 0;
}
if (image.fillAmount < 1)
{
image.fillAmount += 1 * Time.deltaTime / coldTime;
}
}
}
方案二 相比于方案一 变量减少 节省了内存! 以后能减少内存的时候尽量减少,相当于数学中的合并吧!