简体   繁体   English

在Unity3D上的C#中释放按钮后,如何保持播放器方向?

[英]How can I retain player orientation after a button is released in C# on Unity3D?

I'm trying to flip a 3D character to get it to face the correct direction that is pressed. 我正在尝试翻转3D角色以使其面对所按的正确方向。 So far, my code is working: 到目前为止,我的代码正在运行:

    private void OrientAvatar()
{
    if (ControlVector.x > DeadZone)
    {
        Spin = -90;
    }

    if (ControlVector.x < DeadZone)
    {

        Spin = 90;
    }

    if (ControlVector.y > DeadZone)
    {

        Spin = 180;
    }

    Pivot.eulerAngles = new Vector3(Pivot.rotation.x, Spin, Pivot.rotation.z);  
}

However, when the keys are released it'll flip direction to the opposite. 但是,释放按键时,它将向相反的方向翻转。 How can I retain the previous orientation set so that the character model remains facing in the correct direction? 如何保留以前的方向集,以使角色模型保持朝向正确的方向?

I figured it out with a few minor code corrections: 我通过一些小的代码更正找出来了:

private void OrientAvatar()
{
    Debug.Log(ControlVector.x);

    if (ControlVector.x >= DeadZone)
    {
        Spin = -90;
    }

    if (ControlVector.x <= -DeadZone)
    {
        Spin = 90;

    }

    if (ControlVector.y > DeadZone && Ladder)
    {
        Spin = 180;
    }

    Pivot.eulerAngles = new Vector3(Pivot.rotation.x, Spin, Pivot.rotation.z);  
}

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

相关问题 播放器死亡后使按钮出现-Unity3D 4.6 GUI C# - Making a button appear after player death - Unity3D 4.6 GUI C# 玩家在附近时产生AI(Unity3d / C#) - Spawn AI when player is around (Unity3d/C#) (Unity,2D,C#)如何让玩家在需要再次按下按钮之前松开按钮? - (Unity, 2D, C#) How can I make the player let go of a button before needing to press it again? 我如何通过unity3d中的C#脚本关联不同的网格? - How can i relate different meshes through c# script in unity3d? 如何在C#程序中运行“无头”(无GUI)Unity3D游戏? - How can I run a “headless” (no GUI) Unity3D game inside a C# program? 如何在 unity3D、C#、手机游戏中保存和加载关卡? - How I can save and load level in unity3D, C# , Mobile Game? C# 如何在不产生任何垃圾的情况下对列表进行排序(Unity3d) - C# How Can I Sort A List without Generating Any Garbage at All (Unity3d) 如何使用Unity3D检测移动设备上的抖动? C# - How can I detect a shake motion on a mobile device using Unity3D? C# 如何在 Unity3d 中将 C# 组件从一个游戏对象传递到另一个游戏对象 - how can I pass a C# component from one gameobject to another in Unity3d 如何使用模型动态生成模型的纹理图像。 (Unity3D / C#)? - How can I use a model to generate a Texture image of the model dynamically. (Unity3D/C#)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM