如何在Unity 2D中翻转复合字符?

发布于 2025-01-29 16:08:26 字数 153 浏览 2 评论 0 原文

我真的需要Unity 2D的帮助。目标是让玩家在向右行驶时向后翻转。互联网上有很多选择如何通过Sprite渲染来执行此操作。但是问题在于我的角色由部分组成,因为动画是骨头。每个部分都可以翻转。当您打开对象本身的精灵渲染中的翻转时,什么都没有。问题是如何立即发动政变?如果没有,该如何进行部分?

I really need help with Unity 2D. The goal is for the player to flip when going left and back when going right. There are many options on the Internet how to do this through sprite rendering. But the problem is that my character consists of parts, since the animation is bone. Each part can be flipped. And when you turn on flip in the sprite rendering of the object itself, nothing works. The question is how to make a coup at once the entire character? And if not, how to do it in parts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓝咒 2025-02-05 16:08:26

您应该通过刻度进行翻转,它将影响所有组件。它在 noreferrer“ noreferrer”> docs

You should flip via scale, it will effect the all components.It's also metioned in the docs.

等风来 2025-02-05 16:08:26

我确定您在教程中熟悉 input.getAxisRaw(“ Horizo​​ntal”)。以最简单的方式返回字符:

var xAxis = Input.GetAxisRaw("Horizontal");

if (xAxis != 0) transform.localScale = new Vector3(xAxis, 1, 1);

在此脚本中,如果轴不是0(没有按键或停止按下),请设置精灵的 scalex 等于xaxis方向。

I'm sure you are familiar with Input.GetAxisRaw ("Horizontal") in the tutorial. Return the character in the simplest way:

var xAxis = Input.GetAxisRaw("Horizontal");

if (xAxis != 0) transform.localScale = new Vector3(xAxis, 1, 1);

In This script, if Axis is not 0 (no pressed key or stop pressing), sets the ScaleX of the sprite equal to the xAxis direction.

怪我太投入 2025-02-05 16:08:26

正如Oistikbal所说,使用这样的比例:

void Update()
{
    if (Input.GetKeyDown(KeyCode.A))
    {
        transform.localScale = new Vector3(-1, 1, 1); ;

    }

    if (Input.GetKeyDown(KeyCode.D))
    {
        transform.localScale = new Vector3(1, 1, 1); ;

    }
}

按下A/D时,更改了刻度,以使角色翻转。

As oistikbal said, use scaling like this:

void Update()
{
    if (Input.GetKeyDown(KeyCode.A))
    {
        transform.localScale = new Vector3(-1, 1, 1); ;

    }

    if (Input.GetKeyDown(KeyCode.D))
    {
        transform.localScale = new Vector3(1, 1, 1); ;

    }
}

When A/D is pressed the scale is changed so the character is flipped.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文