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


public class Test : MonoBehaviour {


    public string Idle = "Idle";
    public string Attack1 = "Attack1";
    public string Attack2 = "Attack2";
    public string Attack3 = "Attack3";


    public int comboCount = 0;


    private Animator ani;


    void Start()
    {
        ani = this.GetComponent<Animator>();
    }




    void OnGUI()
    {
        if (GUILayout.Button("Attack")) Attack();
    }




    void Attack()
    {
        AnimatorStateInfo info = ani.GetCurrentAnimatorStateInfo(0);
        if (info.IsName(Idle))
        {
            comboCount = 1;
            ani.SetInteger("attack", comboCount);
        }
        if (info.IsName(Attack1) && comboCount == 1)
        {
            comboCount = 2;
        }
        if (info.IsName(Attack2) && comboCount == 2)
        {
            Debug.Log(info.normalizedTime);
            comboCount = 3;
        }
    }


    void NextAttack()
    {
        ani.SetInteger("attack", comboCount);
    }


    void StopAttack()
    {
        comboCount = 0;
        ani.SetInteger("attack", comboCount);
    }

}


使用动画事件处理Combo连击



1.需要注意的点,拥有事件触发方法的脚本必须在Animator组件的对象上。

2.注意触发时间,点击攻击的时候可获取到当前动画播放的normalizedTime,触发NextAttack事件的时间要晚于获取到的normalizedTime。

3.注意动画过度区!!! 不要执行stop方法


相关文章:

  • 2021-08-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-10
  • 2022-01-08
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2022-01-30
  • 2021-06-30
相关资源
相似解决方案