欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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();
    }
}
相关标签: c#基础