https://www.bilibili.com/video/BV1EY4y1Y7Rq?spm_id_from=333.999.0.0
涉及 4个脚本,4段动画(Idle,Attack One,AttackTwo,AttackThree),三个trigger
三个trigger 命名为AttackOne,AttackTwo,AttackThree
AttackOne 是在 idle 到 AttackOne之间
AttackTwo 是在 Transition One 到 Attack Two之间
AttackThree 是在 Transition Two 到Attack three
注意 Transition one 是第一段攻击动画的后半段,Attack one 是整个动画的前半段,其实是一个动画分两段,需要从外面拖两次进来不同命名,调整时间。
同上,Transition Two 和 Attack Two同样原理
如下图所示
4个脚本
为如下,其中comboMainControl挂到你的角色上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class comboMainControl : MonoBehaviour
{
public static comboMainControl instance;
public void Awake()
{
instance = this;
}
public bool inputRecieved;
private void Update()
{
Attack();
}
public void Attack()
{
if (Input.GetKeyDown(KeyCode.K))
{
inputRecieved = true;
}
else
{
inputRecieved = false;
}
}
}
动画控制器里 单击Idle后 在右面add component 可以添加如下脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class idleBehaviour : StateMachineBehaviour
{
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
//override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
//
//}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (comboMainControl.instance.inputRecieved)
{
// Debug.Log("first trigger");
animator.SetTrigger("AttackOne");
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove()
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that processes and affects root motion
//}
// OnStateIK is called right after Animator.OnAnimatorIK()
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that sets up animation IK (inverse kinematics)
//}
}
动画控制器里 单击ITransition One后 在右面add component 可以添加如下脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class transitionOne : StateMachineBehaviour
{
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
// override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
// {
//
// }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (comboMainControl.instance.inputRecieved)
{
animator.SetTrigger("AttackTwo");
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove()
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that processes and affects root motion
//}
// OnStateIK is called right after Animator.OnAnimatorIK()
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that sets up animation IK (inverse kinematics)
//}
}
动画控制器里 单击ITransition Two后 在右面add component 可以添加如下脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class transitionTwo : StateMachineBehaviour
{
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
// override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
// {
// }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
if (comboMainControl.instance.inputRecieved)
{
animator.SetTrigger("AttackThree");
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
//
//}
// OnStateMove is called right after Animator.OnAnimatorMove()
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that processes and affects root motion
//}
// OnStateIK is called right after Animator.OnAnimatorIK()
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
//{
// // Implement code that sets up animation IK (inverse kinematics)
//}
}
一律无脑替换
你就可以流畅的出连招了