简体   繁体   English

为什么 animSetInteger 不能正常工作?

[英]Why doesn't animSetInteger work properly?

I'm working on a mobile 3d game, i've shared a picture from my character's movement script, if you look at it you can see there is an "anim.SetInteger" for each input but the "condition" doen't change to "1" for every direction.我正在开发一款移动 3d 游戏,我分享了我角色移动脚本中的一张图片,如果您查看它,您会看到每个输入都有一个“anim.SetInteger”,但“条件”不会改变每个方向为“1”。 If you guys know what do i need to do that, pls let me know.如果你们知道我需要做什么,请告诉我。

MovementScript MovementScript2 ("Else" part) MovementScript MovementScript2(“其他”部分)

Your else statement only applies to your final if statement.您的else语句仅适用于您的最终if语句。 What's probably happening is that one of your first six if statements is true, so then your Condition animation parameter gets set to 1. But since your final if statement if false, the else block also gets executed, so Condition gets set back to zero within the same game loop iteration.什么是可能发生的事情是一个你的前六if报表是真实的,这样的话你的Condition动画参数被设置为1,因为最终if声明如果否, else块也被执行,那么Condition得到内设置回零相同的游戏循环迭代。

Change all of your middle if statements to else if .将所有中间if语句更改为else if It should be like this:应该是这样的:

if (/* condition 1 */)
{
   anim.SetInteger("Condition", 1);
   // transform = ...
}
else if (/* condition 2 */)
{
   anim.SetInteger("Condition", 1);
   // transform = ...
}
else if (/* condition 3 */)
{
   anim.SetInteger("Condition", 1);
   // transform = ...
}
else
{
   anim.SetInteger("Condition", 0);
   horizontal = 0;
   vertical = 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM