zoukankan      html  css  js  c++  java
  • NGUI的技能冷却实现

      使用NGUI实现技能冷却的原理是这样的:在表示技能的Sprite上加一个半透明的Sprite,将类型设置为filled类型,Fill Dir设置为Radial360,通过程序调节Fill Amount就可以模拟技能从冷却到被活的一段时间内渐变的效果。如下图所示:

      代码中一个标志位isCooling表示是否正在冷却,只有当按下释放技能的按键并且该标志位为false时才可以释放技能,释放完成后isCooling立即变为true,然后冷却的部分在每帧都会减少,直至完全消失。代码如下:

      

     1 using UnityEngine;
     2 using System.Collections;
     3 
     4 public class ReleaseSkill : MonoBehaviour {
     5     UISprite skillSprite;   //负责技能冷却
     6     public float releaseSpeed = 0.5f;
     7     public float needMP = 30f;
     8     public float totalMP = 100f;
     9     public GameObject cardPrefab;
    10     public GameObject parent;
    11 
    12     bool isCooling;                  //是否正在冷却
    13     // Use this for initialization
    14     void Start () {
    15         skillSprite = transform.GetChild(0).GetComponent<UISprite> ();
    16 
    17         skillSprite.fillAmount = 0;
    18         isCooling = true;
    19 
    20     }
    21     
    22     // Update is called once per frame
    23     void Update () {
    24         if (Input.GetKeyDown (KeyCode.M)) {
    25             if (!isCooling && totalMP > needMP) {
    26                 //释放技能
    27                 totalMP -= 20;
    28                 
    29                 //技能完全冷却
    30                 skillSprite.fillAmount = 1;
    31                 isCooling = true;
    32             } 
    33         }
    34 
    35         if (isCooling) {
    36             //经过一段时间冷却技能
    37             skillSprite.fillAmount -= releaseSpeed * Time.deltaTime;
    38             if(skillSprite.fillAmount <= 0)
    39             {
    40                 skillSprite.fillAmount = 0;
    41                 isCooling = false;
    42             }            
    43         }
    44     }
    45 }
    ReleaseSkill
  • 相关阅读:
    1260. [CQOI2007]涂色【区间DP】
    2733. [HNOI2012]永无乡【平衡树-splay】
    1087. [SCOI2005]互不侵犯King【状压DP】
    1026. [SCOI2009]windy数【数位DP】
    1066. [SCOI2007]蜥蜴【最大流】
    luogu P2776 [SDOI2007]小组队列
    cogs 717. [SDOI2007] 小组队列
    luogu P1160 队列安排
    2612. [FHZOI 2017]被窃的项链
    codevs 3336 电话网络 (2)
  • 原文地址:https://www.cnblogs.com/kylinxue/p/4559112.html
Copyright © 2011-2022 走看看