【问题标题】:Why the Unity animation doesn't work on the horizontal side?为什么 Unity 动画在水平侧不起作用?
【发布时间】:2014-10-26 13:44:33
【问题描述】:

我使用 Unity 开发了一款 2D 游戏。我使用了 EasyTouch 包。当使用左右键时,通过设置左侧的flag = 3和右侧的flag = 4来触发动画。但是,如果我改用操纵杆,左侧和右侧的动画都不起作用。有人可以帮我解决这个问题吗?非常感谢。

void Movement()
{   
    if(joystick.JoystickAxis.x<0)
    {

    //if (Input.GetAxisRaw("Horizontal")<0) {
        anim.SetInteger("flag",3);
        transform.Translate(Vector3.left*speed*Time.deltaTime);

    }

    if(joystick.JoystickAxis.x>0)
    {
        //if(Input.GetAxisRaw("Horizontal")>0) {
        anim.SetInteger("flag",4);
        transform.Translate (Vector3.right*speed*Time.deltaTime);
    }

    if(joystick.JoystickAxis.y<0)
    {
         anim.SetInteger("flag",1);
         //if (Input.GetAxisRaw("Vertical")<0) {
         transform.Translate (Vector3.down*speed*Time.deltaTime);

    }

    if(joystick.JoystickAxis.y>0)
    {
        anim.SetInteger("flag",2);
        //if (Input.GetAxisRaw("Vertical")>0) {
        transform.Translate (Vector3.up*speed*Time.deltaTime);
    }
}

【问题讨论】:

    标签: unity3d unityscript


    【解决方案1】:

    您也可以为您的脚本使用 Input.GetAxis("Horizo​​ntal") 方法。但为此,您必须更改项目输入设置。为此,请按以下步骤操作:

    • 转到编辑->项目设置->输入
    • Inspector Menu 下,您会找到 Axes 列表。
    • Axes下有一个Horizo​​ntal选项。
    • Horizo​​ntal下有一个Type下拉菜单。
    • 选择操纵杆轴
    • Type 旁边是Axis。选择X轴

    现在尝试像这样测试您的脚本。

    if (Input.GetAxisRaw("Horizontal")<0) {
        anim.SetInteger("flag",3);
        transform.Translate(Vector3.left*speed*Time.deltaTime);
    
    }
    

    您可以寻求任何进一步的帮助。

    【讨论】:

      【解决方案2】:

      最后,我找到了答案:因为我把Movement()函数放在了Update()中。这意味着每次我使用操纵杆时,它都会更新动画。所以,水平动画总是被垂直动画代替。 这是修改后的版本:
      无效运动() {
      if(joystick.JoystickAxis.xspeedTime.deltaTime); } if(joystick.JoystickAxis.x>Mathf.Abs(joystick.JoystickAxis.y)){ anim.SetInteger("标志",4); transform.Translate (Vector3.rightspeedTime.deltaTime); } if(joystick.JoystickAxis.yspeedTime.deltaTime); } if(joystick.JoystickAxis.y>Mathf.Abs(joystick.JoystickAxis.x)){ anim.SetInteger("标志",2); transform.Translate (Vector3.upspeedTime.deltaTime); } }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-27
        • 2020-08-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多