【问题标题】:Rotation Values getting mixed up C#旋转值混淆 C#
【发布时间】:2016-09-30 14:08:47
【问题描述】:

我正在尝试使用 C# 和 Unity 创建一个简单的游戏机制,它允许玩家向右转动 45 度,然后将他们的新旋转设置为 -45。它有点工作:

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour
{
    public float speed = 215f;

    private bool isLeft = false;

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (isLeft == false)
            {
                transform.rotation = Quaternion.Euler(90, 45,0);
                isLeft = true;
                Debug.Log("Turned Right");
            }
            else
            {

                transform.rotation = Quaternion.Euler(90, 0, 0);

                // No matter what I put as the x value, it always sets it to the z, 
                // for example: if I put 
                // transform.rotation = Quaternion.Euler(90, 270, 0); 
                // the position would be 90, 0, 270.
                Debug.Log("Turned Left");
                isLeft = false;
            }
        }
    }
}

这就是我想要发生的事情:

第一次点击:旋转值设置为90, 45, 0

第二次点击:旋转值设置为90, -45, 0

我是不是用错了命令?

【问题讨论】:

  • 如果你改变这一行:transform.rotation = Quaternion.Euler(90, 0, 0); 这个transform.rotation = Quaternion.Euler(90, -45, 0); 应该可以解决你的问题
  • 谢谢,我觉得自己很蠢 :p 成功了 :)
  • 我发布为答案,请标记为正确:)

标签: c# unity3d rotation


【解决方案1】:

如果你改变这一行: . transform.rotation = Quaternion.Euler(90, 0, 0);对于这个 . transform.rotation = Quaternion.Euler(90, -45, 0); 应该能解决你的问题。

编码愉快!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多