技能的施放和人物动画的播放以及技能冷却效果(NGUI)

技能是一个Button按钮,需要满足以下要求:

一.技能的冷却

1.当鼠标放上与移开时,自适应缩放大小,添加UI Button Scale即可

2.播放声音

3.技能的冷却效果:1.显示遮罩2.冷却时不能再进行点击

1.在Skill下添加一个Mask遮罩,选择 该技能的Sprite,将颜色ColorI Tint更改为灰色

技能有冷却,普通攻击不需要冷却,所以判断是否有子物体Mask即可判断是否是技能,冷却效果通过Mask.fillAmount来实现

2.不能被点击:移除碰撞效果,即collider设置为false

二.技能的施放

1.在技能被按下的时候,找到player,进行player动作的播放

 

技能

   public PosType posType = PosType.Basic;

    private PlayerAnimation playerAnim;
    //冷却技能
    public float coldTime = 4;
    private float coldTimer = 0;//技能冷却的剩余时间
    private UISprite maskSprite = null;

    private UIButton btn;
    void Start()
    {
        //这样子会优化查找,只需查找一次player即可
        playerAnim = TranscriptManager._instance.player.GetComponent<PlayerAnimation>();
        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;//更新mask的fillAmount
            if (coldTimer <= 0)
            {
                Enable();
            }
        }
        else//冷却完成
        {
            maskSprite.fillAmount = 0;//取消mask
        }


    }


    void OnPress(bool isPress)
    {
        playerAnim.OnAttackButtonClick(isPress, posType);
        if (isPress && maskSprite != null)//被按下,普通技不能被冷却
        {
            coldTimer = coldTime;
            Disable();
        }

    }


    void Disable()//技能按钮禁止被点击
    {
        GetComponent<Collider>().enabled = false;
        btn.SetState(UIButtonColor.State.Normal, true);
    }

    void Enable()//技能按钮允许被点击
    {
        GetComponent<Collider>().enabled = true;
    }

 

人物动作

 private Animator anim;
    
    void Awake()
    {
        anim = this.GetComponent<Animator>();
    }

	public void OnAttackButtonClick(bool isPress,PosType posType)
    {
        if (posType == PosType.Basic)
        {
            if (isPress)
            {
                anim.SetTrigger("Attack");
            }
        }
        else
        {
            anim.SetBool("Skill" + (int)posType, isPress);//按下就触发
      
        }
     
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值