对角线运动和动画统一

时间:2016-02-20 23:13:22

标签: c# unity3d unity5

我是c#的新手,正在开展自上而下的2D冒险游戏。我让我的播放器向8个方向移动,动画师在4个主要方向上工作(N,E,S,W)。

我正在尝试在动画师中设置混合树以进行对角移动,但我无法设置它。

这是我的剧本。

public void PlayerAnimation(float moveHorizontal, float moveVertical, Animator anim, Player_Manager _PMS){
// IF we are moving we set the animation IsMoving to true
if(moveHorizontal != 0 || moveVertical != 0){
anim.SetBool("IsMoving", true);
}else{
anim.SetBool("IsMoving", false);
}

// We are wanting to go in the positive X direction.
if(moveHorizontal > 0){
// IF we have invert X on we adjust a different animation.
if(_PMS.invertX){
anim.SetInteger("Direction", 2);
}else{
anim.SetInteger("Direction", 4);
}
// We are wanting to move in the negative X direction.
}else if(moveHorizontal < 0){
// IF we have invert X on we adjust a different animation.
if(_PMS.invertX){
anim.SetInteger("Direction", 4);
}else{
anim.SetInteger("Direction", 2);
}
// We are wanting to move in the negative Y direction.
}else if(moveVertical < 0){
// IF we have invert Y on we adjust a different animation.
if(_PMS.invertY){
anim.SetInteger("Direction", 1);
}else{
anim.SetInteger("Direction", 3);
}
}else if(moveVertical > 0){
// IF we have invert Y on we adjust a different animation.
if(_PMS.invertY){
anim.SetInteger("Direction", 3);
}else{
anim.SetInteger("Direction", 1);
}
}else if(moveHorizontal > 0 || moveVertical < 0){

if(_PMS.invertX || _PMS.invertY){
anim.SetInteger("Direction", 7);
}else{
anim.SetInteger("Direction", 5);
}

}
}

我正在使用“和”运算符为SE运动调用x和y轴(最后一个语句),但是当我在动画师中设置它时它不会注册。还有另一种方法我应该称之为对角线运动吗?

0 个答案:

没有答案