一、模型设置相关
1.2.动画片段
二、动画控制器相关
1.2.场景设置
三、控制脚本
public void move2(Vector2 v) {
Vector3 dir = new Vector3 (v.x,0,v.y);
Quaternion quaDir = Quaternion.LookRotation(dir,Vector3.up);
// 判段当前朝向
float curRotateY = transform.rotation.eulerAngles.y;
// 目标朝向
float destRotateY = quaDir.eulerAngles.y;
AnimatorStateInfo stateinfo = anim.GetCurrentAnimatorStateInfo(0);
//string name = anim.GetCurrentAnimatorClipInfo (0) [0].clip.name;
Debug.Log ("destRotateY :" + destRotateY + " curRotateY: " + curRotateY);
// 误差控制 ###误差越大 开始转弯和恢复转弯 rotate带来的影响越小###
if (Mathf.Abs (curRotateY - destRotateY) <= 20) {
if (stateinfo.IsName("idle")) {
Debug.LogError ("走路idle");
anim.Play ("zou");
}
if (stateinfo.IsName ("zhuanzheng")) {
//靠状态机变化来切换动画
Debug.LogError ("走路zhuanzheng");
anim.SetInteger ("zhuan2zou",1);
}
if (stateinfo.IsName ("zhuanfan")) {
//靠状态机变化来切换动画
Debug.LogError ("走路zhuanfan");
anim.SetInteger ("zhuan2zou",2);
}
// ###加入开始转弯动作补充的两个 start ###
if (stateinfo.IsName ("zoustart")) {
//靠状态机变化来切换动画
Debug.LogError ("走路zhuanfan");
anim.SetInteger ("zhuan2zou",4);
}
if (stateinfo.IsName ("zoustart1")) {
//靠状态机变化来切换动画
Debug.LogError ("走路zhuanfan");
anim.SetInteger ("zhuan2zou",3);
}
// ###加入开始转弯动作补充的两个 end ###
} else {
if (Mathf.Abs (curRotateY - destRotateY) <= 180) {
if (curRotateY < destRotateY) {
//
anim.SetInteger ("zhuan2zou", 0);
//anim.Play ("zhuanzheng");
if (!stateinfo.IsName ("zhuanzheng") && !stateinfo.IsName ("zoustart1"))
anim.Play ("zoustart1");
Debug.LogError ("正转圈 ");
} else if (curRotateY > destRotateY) {
anim.SetInteger ("zhuan2zou", 0);
//anim.Play ("zhuanfan");
if (!stateinfo.IsName ("zhuanfan") && !stateinfo.IsName ("zoustart"))
anim.Play ("zoustart");
Debug.LogError ("反转圈");
}
} else {
if (curRotateY < destRotateY) {
anim.SetInteger ("zhuan2zou", 0);
//anim.Play ("zhuanfan");
if (!stateinfo.IsName ("zhuanfan") && !stateinfo.IsName ("zoustart"))
anim.Play ("zoustart");
Debug.LogError ("反转圈");
} else if (curRotateY > destRotateY) {
anim.SetInteger ("zhuan2zou", 0);
//anim.Play ("zhuanzheng");
if (!stateinfo.IsName ("zhuanzheng") && !stateinfo.IsName ("zoustart1"))
anim.Play ("zoustart1");
Debug.LogError ("正转圈 ");
}
}
}
}