如何实现技能冷却效果

    xiaoxiao2021-03-25  211

    首先我们需要一个技能图片!

    然后!我们需要一个透明的图片!例如:

    然后!让透明的图片遮住技能

    接着把透明图片的Image属性改成如图所示

    代码如下

    using UnityEngine; using System.Collections; using UnityEngine.UI; public class skill_cd : MonoBehaviour { Image image; bool isstartcd = false; public float cdtime =2; private float timer = 0; void Start () { image = transform.Find ("cd_Image").GetComponent<Image> (); } void Update () { if (isstartcd) { timer += Time.deltaTime; image.fillAmount = (cdtime - timer) / cdtime; if (timer >= cdtime) { timer = 0; isstartcd = false; } } } public void OnClick(){ isstartcd = true; }

    }

    转载请注明原文地址: https://ju.6miu.com/read-16561.html

    最新回复(0)