简体   繁体   English

为什么我的动画在Unity中倒退?

[英]Why are my animations backwards in Unity?

Okay so here is a video showing the problem that is pretty self explanatory https://youtu.be/7701UK0ijy4 好的,这是一个展示问题的视频,可以自我解释https://youtu.be/7701UK0ijy4

My problem is purely that when I switch to the Running Left animation, it still plays the Running Right animation instead 我的问题纯粹是,当我切换到“跑步向左”动画时,它仍会播放“跑步向右”动画

Before you read this list just know, none if it had any effect. 在阅读此列表之前,您只知道它没有作用。 So far, I have tried setting Speed of Main_Run_Left to -1. 到目前为止,我已经尝试将Main_Run_Left的Speed设置为-1。 I have checked the Mirror box. 我已选中“镜像”框。 I have deleted all animations and reset them. 我已删除所有动画并重置它们。

Edit: I switched Running_Left animation with a different monster animation and it kinda worked briefly? 编辑:我用另一个怪物动画切换了Running_Left动画,这有点短暂吗? as in it was playing running_Left with the other monster animation set instead? 就像在播放running_Left时设置了另一个怪物动画吗? Like I said briefly, it went back to running right while going left. 就像我简短地说过的那样,它在左转时又回到了右转。

public Animator anim;


// Update is called once per frame
void Update()
{
    horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

    if (horizontalMove > .001)
    {
        anim.SetBool("Running Right", true);
        anim.SetBool("Running Left", false);
        anim.SetBool("Chillin", false);
    }
    else if (horizontalMove < -.001)
    {
        anim.SetBool("Running Left", true);
        anim.SetBool("Running Right", false);
        anim.SetBool("Chillin", false);
    }
    else
    {
        anim.SetBool("Chillin", true);
        anim.SetBool("Running Left", false);
        anim.SetBool("Running Right", false);

    }

What you're doing is kind of weird. 您正在做的事情很奇怪。 You have a walking right animation AND a walking left animation, even though they're mirror flips of each other. 您有向右行走的动画和向左行走的动画,即使它们彼此是镜像翻转。 How about deleting the walking left animation and renaming the other one to just 'Walking'? 删除向左走的动画,然后将另一个重命名为“正在走动”怎么样? Then delete all the bools in your animator and replace them with a single one called 'Moving'. 然后删除动画器中的所有布尔并将其替换为一个称为“移动”的布尔。 The condition to transition from chillin to walking is whether the 'Moving' bool is true, and vice versa. 从chillin过渡到walking的条件是“ Moving”布尔值是否正确,反之亦然。 Then in code, you flip the sprite when its horizontal is less than zero. 然后在代码中,当精灵的水平小于零时翻转精灵。 I posted a script below that shows what I'm talking about. 我在下面发布了一个脚本,该脚本显示了我在说什么。

using UnityEngine;

public class Player : MonoBehaviour
{
[SerializeField]
private float _speed;

private Rigidbody2D _rb;
private Animator _anim;
private SpriteRenderer _sprite;

void Start()
{
    _rb = GetComponent<Rigidbody2D>();
    _anim = GetComponent<Animator>();
    _sprite = GetComponent<SpriteRenderer>();
}

void FixedUpdate()
{
    Move();
}

private void Move()
{
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    Vector2 movement = new Vector2(horizontal, vertical);
    _rb.velocity = movement * _speed;

    _anim.SetBool("Moving", horizontal != 0);

    if (horizontal != 0)
        Flip(horizontal > 0);

}

private void Flip(bool facingRight)
{
    _sprite.flipX = !facingRight;
}

}

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

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