using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
public class filedskill : MonoBehaviour
{
public float f = 3;//决定冷却时间3秒
public bool b;//作为触发条件
public float timer=0;//判断1秒
public void Update()
{
this.gameObject.GetComponent<Button>().onClick.AddListener(onclick);//当点击这个图片的时候的时候触发的事件是调用函数onclick,将b=true
if(Input.GetKeyDown(KeyCode.F))//如果键盘按下了F效果也是将b=ture
{
b = true;
}
if (b)//如果b=true,则执行
{
timer += Time.deltaTime;//经过了1S,每当timer累加到1则表示经过了1秒,累加到2表示经过了2秒.......
this.gameObject.GetComponent<Image>().fillAmount = (f - timer) / f;//3秒-x秒/3秒
}
if (this.gameObject.GetComponent<Image>().fillAmount==0)//当技能冷却时间为0的时候,就是无冷却的时候
{
b = false;//先停止timer的累加和
unity(UGUI)技能冷却 代码详解
最新推荐文章于 2025-03-06 22:57:42 发布