我有一个汽车游戏,只能沿 x 轴和 z 轴行驶。如果汽车开到正 z (rotation == 0),那么它必须做一些事情,如果它开到正 x (rotation == 90),那么它必须做其他事情,依此类推。
if (transform.rotation.eulerAngles.y == 0)
{
richtung = 0;
Debug.Log("north");
}
if (transform.rotation.eulerAngles.y == 90)
{
richtung = 1;
Debug.Log("east");
}
if (transform.rotation.eulerAngles.y == -180 || transform.rotation.y == 180)
{
richtung = 2;
Debug.Log("south");
}
if (transform.rotation.eulerAngles.y == -90)
{
richtung = 3;
Debug.Log("west");
}
它适用于北方和东方,但南方和西方不适用。即使我用旋转的汽车启动程序 == -180 || 180.我做错了什么?谢谢!