【发布时间】:2020-12-14 23:40:24
【问题描述】:
有一个UI按钮,当你点击它时,同一个按钮平滑旋转90°并停止旋转,当你再次按下按钮时,执行动作。 但是在旋转等于 360°(代码为 0f)后,按钮不会进一步旋转。我不知道为什么会这样。
public GameObject Botton;
private float BottonRotationZ;
public void Rotate()
{
if (Botton.transform.eulerAngles.z == 0f)
{
LeanTween.rotateZ(Botton,90f,0.5f);
}
else if (Botton.transform.eulerAngles.z == 90f)
{
LeanTween.rotateZ(Botton,180f,0.5f);
}
else if (Botton.transform.eulerAngles.z == 180f)
{
LeanTween.rotateZ(Botton,270f,0.5f);
}
else if (Botton.transform.eulerAngles.z == 270f)
{
LeanTween.rotateZ(Botton,0f,0.5f);
}
}
【问题讨论】:
-
这看起来不像 C...
-
打印角度以确定它是什么。也许它只旋转到 359.5°
-
@Weather Vane 给出而不是 360:1.001791E-05
-
我正要问
float是否完全准确,直到我注意到它的步长为0.5,而float完全可以表示。也许是因为它在内部使用数学 弧度 并转换为人类 度。请参阅Is floating point math broken? 和Why Are Floating Point Numbers Inaccurate?
标签: unity3d