unity 技能按键冷却
程序员文章站
2022-04-03 08:36:12
...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Skill : MonoBehaviour
{
public float SkillTime=5;
private float SkillTimeNow=5;
private bool SkillCanShow=true;
public Image Image;
// Start is called before the first frame update
void Start()
{
}
private void TimeNow()
{
Image.fillAmount = SkillTimeNow / SkillTime;
if (SkillTimeNow >= 5)
{
SkillCanShow = true;
}
else
{
SkillTimeNow += Time.deltaTime;
SkillCanShow = false;
}
}
public void OnSikll()
{
if (SkillCanShow==true)
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
SkillCanShow = false;
SkillTimeNow = 0;
}
}
}
// Update is called once per frame
void Update()
{
TimeNow();
OnSikll();
}
}