协程
row 1
2
3
4
5
6
7
8
9//函数
public IEnumerator BusyFor(float _seconds)
{
isBusy = true;
yield return new WaitForSeconds(_seconds);
isBusy = false;
}
//调用
player.StartCoroutine("BusyFor",.15f);
此方法将暂停对象数秒而不影响整个游戏本身动画 trigger
row 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20//在playerState中创建public函数
public virtual void AnimationFinishTrigger()
{
triggerCalled = true;
}
//在player中创建方法结束该状态
public void AnimationTrigger () => StateMachine.currentState.AnimationFinishTrigger();
//trigger文件中设立该函数
public class PlayerAnimationTrigger : MonoBehaviour
{
private Player player => GetComponentInParent<Player>();
private void AnimationTrigger()
{
player.AnimationTrigger();
}
}
//最后在动画中添加动作帧并嵌入函数调用更改攻速的方式
row 1
player.animator.speed = 1.2f;//攻速
设立玩家攻击时人物的抖动
row 1
2
3
4
5// player 中
public Vector2[] attackMovement;
//playerPrimaryAttackState中
player.SetVelocity(player.attackMovement[comboCounter].x * attackDir, player.attackMovement[comboCounter].y);
然后设立值