700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 技能冷却: 判断技能 释放技能

技能冷却: 判断技能 释放技能

时间:2019-01-04 22:25:52

相关推荐

技能冷却: 判断技能 释放技能

技能冷却: 判断技能 释放技能

using System.Collections; using System.Collections.Generic; using UnityEngine; public class skillButton : MonoBehaviour {playernimator playerAnimation;public PosType posType = PosType .Basic;//根据这个枚举位置判断public float coldTime = 4; public float coldTimer = 0; //剩余的冷却时间 UISprite maskSprite; UIButton btn; void Start () {//调用技能播放的一个方法 根据位置判断 playerAnimation = TranscriptManager ._instance.player.GetComponent< playernimator >(); if (transform.Find( "mask" )) //子图 {maskSprite = transform.Find( "mask" ).GetComponent< UISprite >(); } //按钮等于脚本挂载对象的按钮 btn = this .GetComponent< UIButton >(); }void Update () {if (maskSprite== null ) //没有子图的话就不用技能冷却 说明是普通攻击 return ; //直接返回 if (coldTimer>0) {//每秒开始冷却 coldTimer -= Time .deltaTime; maskSprite.fillAmount = coldTimer / coldTime; //填方量=剩余的冷却时间/冷却时间 if (coldTimer<=0) //剩余的冷却时间小于0 启用按钮 {Enable(); }} else {maskSprite.fillAmount = 0; } } void OnPress( bool isPress) {playerAnimation.OnAttackButtonClick(isPress, posType); if (isPress&&maskSprite!= null ) {coldTimer = coldTime; Dsiable(); } } void Dsiable() {//设为正常 btn.SetState( UIButton . State .Normal, true ); //禁用 GetComponent< Collider >().enabled = false ; } private void Enable() { //激活 GetComponent< Collider >().enabled = true ; } }

释放技能:

using System.Collections; using System.Collections.Generic; using UnityEngine; public class playernimator : MonoBehaviour {private Animator anim; void Start () {anim = GetComponent< Animator >();} public void OnAttackButtonClick( bool isPress, PosType posType) {if (posType == PosType .Basic) {print(posType); if (isPress) anim.SetTrigger( "attack" ); } else {print(posType); print(666); anim.SetBool( "skill" + ( int )posType, isPress); } } }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。