设置一个布尔值isattack,初始值为false
当按下“J”时,isattack=true
再设置一个计数器,int值counter
现在有连击的三个动画,设为a,b,c
abc的共同触发条件是在地面上,isattack=true
不同的是,a的counter值为0,b为1,c为2
在每个动画末尾添加事件,引用下面函数
public void attackover()
{
isattack = false;
counter++;
if(counter>2)
counter = 0;
为了使未触发连击时能从头开始播放动画,需要一个计时器
combotimewindow -= Time.deltaTime;
当combotimewindow<0时,counter=0
给个初始值1,每次按下“J”就重置
具体代码
[Header("attack info")]
[SerializeField] private float combotime;
private float combotimewindow;
private bool isattack;
private int counter;
void Update()
{
combotimewindow -= Time.deltaTime;
if (combotimewindow < 0)
counter = 0;
}
private void checkinput()
{
XInput = Input.GetAxisRaw("Horizontal");
if (Input.GetKeyDown(KeyCode.Space))
jump();
if (Input.GetKeyDown(KeyCode.J))
{
isattack = true;
combotimewindow = combotime;
}
}