【发布时间】: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 成功了 :)
-
我发布为答案,请标记为正确:)