美文网首页
8、技能冷却实现

8、技能冷却实现

作者: GameObjectLgy | 来源:发表于2020-09-30 09:19 被阅读0次

第一种技能

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillOne : MonoBehaviour
{
    public Image MaskImage;
    public Button MaskButton;
    public Text CDTimeText;
    //累加器
    private float Times = 0f;
    public float CD_Time = 0f;//技能时间
    private bool ButtonMashSwitch = false;

    void Start()
    {
        MaskImage.gameObject.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (ButtonMashSwitch)//通过一个开关来判定是不是进入冷却阶段
        {
            Times += Time.deltaTime;

            MaskImage.fillAmount = Times / CD_Time;
            CDTimeText.text = Math.Round(CD_Time - Times, 1).ToString();
            if (Times >= CD_Time)
            {
                CDTimeText.text = null;
                ButtonMashSwitch = false;
                MaskImage.fillAmount = 1;
                Times = 0f;
                //MaskButton.interactable = true;
                MaskButton.enabled = true;
                MaskImage.gameObject.SetActive(false);
            }
        }
    }

    public void OnClickBtn()
    {
        MaskImage.gameObject.SetActive(true);
        //MaskButton.interactable = false;//使Button失效并且变灰
        MaskButton.enabled = false;//仅仅使Button失效
        ButtonMashSwitch = true;
    }

}
image.png
4.gif

相关文章

网友评论

      本文标题:8、技能冷却实现

      本文链接:https://www.haomeiwen.com/subject/peieuktx.html