Ngui _CD技能特效

本文介绍了一个简单的Unity技能冷却系统实现方法。通过控制UISprite组件的fillAmount属性来模拟技能冷却效果,使用Input.GetKeyDown方法监听键盘输入触发技能,并通过一个布尔变量isColding判断技能是否处于冷却状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using UnityEngine;
using System.Collections;

public class Skill : MonoBehaviour {
public float coldTime=2;//技能冷却时间
private UISprite sprite;
bool isColding=false;//标志位,判断技能是否在冷却。
// Use this for initialization
void Start () {
sprite = transform.Find ("Sprite").GetComponent<UISprite> ();//得到sprite上的UISprite组件。Unity编程,基本的套路就是得到组件,控制他身上的属性。

}

// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.A)&&isColding==false){
sprite.fillAmount=1;
isColding =true;
}
if(isColding){
sprite.fillAmount-= 1f/coldTime*Time.deltaTime;//计算每一帧要减去的东西。
if(sprite.fillAmount<=0){
sprite.fillAmount=0;
isColding=false;
}
}
}
}

转载于:https://www.cnblogs.com/ouyangJJ/p/5808313.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值