C# 3d Unity Player对象沿同一方向移动
我有一个问题,玩家在方向上移动,但角色的动画保持不变。因此,如果我单击“w”键,播放器将向前运行动画。但当我向后单击“s”时,角色不会旋转到它只向后移动/滑动的方向,角色面朝前,没有动画。请帮忙C# 3d Unity Player对象沿同一方向移动,c#,unity3d,C#,Unity3d,我有一个问题,玩家在方向上移动,但角色的动画保持不变。因此,如果我单击“w”键,播放器将向前运行动画。但当我向后单击“s”时,角色不会旋转到它只向后移动/滑动的方向,角色面朝前,没有动画。请帮忙 public class Player : MonoBehaviour { private Animator anim; private CharacterController controller; public float speed = 600.
public class Player : MonoBehaviour {
private Animator anim;
private CharacterController controller;
public float speed = 600.0f;
public float turnSpeed = 400.0f;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
private Vector3 curLoc;
void Start () {
controller = GetComponent <CharacterController>();
anim = gameObject.GetComponentInChildren<Animator>();
}
void Update (){
if (Input.GetKey ("w")) {
anim.SetInteger ("AnimationPar", 1);
} else {
anim.SetInteger ("AnimationPar", 0);
}
if (Input.GetKey("s"))
{
anim.SetInteger("Condition", 1);
}
else
{
anim.SetInteger("Condition", 0);
}
if (controller.isGrounded){
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
}
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
if (Input.GetKey(KeyCode.S))
{
}
}
}
公共类玩家:单行为{
私人动画师;
专用字符控制器;
公共浮子速度=600.0f;
公共浮子转速=400.0f;
专用矢量3移动方向=矢量3.0;
公共浮子重力=20.0f;
私有向量3;
无效开始(){
controller=GetComponent();
anim=gameObject.getComponentChildren();
}
无效更新(){
if(Input.GetKey(“w”)){
anim.SetInteger(“AnimationPar”,1);
}否则{
anim.SetInteger(“AnimationPar”,0);
}
if(Input.GetKey(“s”))
{
动画设置整数(“条件”,1);
}
其他的
{
anim.SetInteger(“条件”,0);
}
if(controller.isground){
移动方向=transform.forward*输入.GetAxis(“垂直”)*速度;
}
浮动旋转=输入。GetAxis(“水平”);
transform.Rotate(0,turn*turnSpeed*Time.deltaTime,0);
控制器移动(移动方向*时间增量);
moveDirection.y-=重力*时间增量;
if(Input.GetKey(KeyCode.S))
{
}
}
}
您需要向动画师展示动画是如何播放和转换的。在玩游戏时只需打开animator,检查“条件”参数所在的位置是否正在玩动画。也请检查动画过渡。此外,我建议您在按下“s”时将值“AnimationPar”更改为0
if (Input.GetKey("s"))
{
anim.SetInteger ("AnimationPar", 0);
anim.SetInteger("Condition", 1);
}
不,你在哪儿叫它转过来的