运行效果:
先实现上半身动,按下空格键之后加上了下半身走路的动画
1.
最上面的base层,我们创建出来是空的,不要管他。
下面的两个动画层,分别存放了一个clip,show是有挥剑的动作,run是有跑步的动作。
2.
创建一个Mask,如下:
点击哪个部分,哪个部分就变为红色,代表这里是不动的状态
3.
给到ShowLayer层
4.
再创建一个mask给到run层,只能下半身动
5.
代码部分,挂载到角色身上
public class Ctl : MonoBehaviour
{
Animator animator;
int baseLayer;
int runLayer;
int showLayer;
private void Awake()
{
animator = GetComponent<Animator>();
baseLayer = animator.GetLayerIndex("base");
showLayer = animator.GetLayerIndex("ShowLayer");
runLayer = animator.GetLayerIndex("run");
}
void Start()
{
//显示上半身
animator.SetLayerWeight(baseLayer, 0f);
animator.SetLayerWeight(showLayer, 1f);
}
// Update is called once per frame
void Update()
{
//按下空格键
//显示下半身动,同时上面的上半身动画也在执行(因为上面的权重还是为1)
if(Input.GetKeyDown(KeyCode.Space))
{
animator.SetLayerWeight(runLayer, 1f);
}
}
}