在Unity 2D掷2D精灵动画 [英] Flipping a 2D Sprite Animation in Unity 2D

查看:238
本文介绍了在Unity 2D掷2D精灵动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于2D雪碧的动画一个快速的问题,我一直没能找到任何地方明确回答:

I've got a quick question regarding 2D Sprite animations that I haven't been able to find specifically answered anywhere:

我有散步的动画到正确的精灵。但是,我明明想翻转动画的左边,当他走左(2D横向滚动条)。

I have a sprite with walk animations to the right. However, I obviously want to flip the animation to the left when he walks left (2D side-scroller).

我可以轻松地翻转精灵本身,但是使用 transform.localscale.x ,只有翻转精灵。不是动画片段。

I can easily flip the sprite itself, using transform.localscale.x, however, that only flips the sprite. Not the animation clip.

所以,虽然精灵翻转,动画片段开始播放一分钟,它翻转后右(作为唯一的动画短片我是正确的面对精灵)。

So, while the sprite flips, the minute the animation clip begins playing, it flips back right (as the only animation clip I have is for the right facing sprite).

时要做到这一点翻转在Photoshop中精灵的唯一途径,或者是有办法做到这一点的统一?

Is the only way to do this to flip the sprites in Photoshop, or is there a way to do it in Unity?

谢谢!

推荐答案

我终于理解了它这样做的:

I finally figured it out by doing this:

void Flip()
{
    // Switch the way the player is labelled as facing
    facingRight = !facingRight;

    // Multiply the player's x local scale by -1
    Vector3 theScale = transform.localScale;
    theScale.x *= -1;
    transform.localScale = theScale;
}

这是从团结的2D平台游戏的例子。

This is from Unity's 2D Platformer example.

这篇关于在Unity 2D掷2D精灵动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆