[英]Why won't my unity controller work properly?
我是统一的新手,我遇到了动画师 controller 组件的问题。
按下 Z 按钮时,我的播放器应该开始向前移动,但 animation 不会启动。
这是我的代码:
public Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Z))
{
anim.SetFloat("MoveX",0.17f);
Debug.Log("hhh");
}
else
{
anim.SetFloat("MoveX", 0);
}
if (Input.GetKey(KeyCode.Q))
{
anim.SetFloat("MoveZ",0.208f);
Debug.Log("stiw");
}
else
{
anim.SetFloat("MoveZ", 0);
}
if (Input.GetKey(KeyCode.S))
{
anim.SetFloat("MoveX",-0.166f);
}
else
{
anim.SetFloat("MoveX", 0);
}
if (Input.GetKey(KeyCode.D))
{
anim.SetFloat("MoveZ",-0.2f);
}
else
{
anim.SetFloat("MoveZ", 0);
}
}
向后移动和向右开始工作正常,除了向前和向左移动
这是我的混合树的屏幕截图
再看看你在Update
中的情况,想想如果你按下前进按钮(Q)会发生什么:
anim.SetFloat("MoveZ",0.208f);
anim.SetFloat("MoveZ",0);
现在看到了吗? 最后两项检查会否决前两项并“吃”您输入的内容;)
您应该使您的案例更加独特,例如
void Update()
{
if (Input.GetKey(KeyCode.Z))
{
anim.SetFloat("MoveX",0.17f);
Debug.Log("hhh");
}
else if (Input.GetKey(KeyCode.S))
{
anim.SetFloat("MoveX",-0.166f);
}
else
{
// Only reached if neither Z nor S is pressed!
anim.SetFloat("MoveX", 0);
}
if (Input.GetKey(KeyCode.Q))
{
anim.SetFloat("MoveZ",0.208f);
Debug.Log("stiw");
}
else if (Input.GetKey(KeyCode.D))
{
anim.SetFloat("MoveZ",-0.2f);
}
else
{
// Only reached if neither Q nor D is pressed!
anim.SetFloat("MoveZ", 0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.