我想在每次单击按钮时将图像旋转 90º。我的问题是,当我点击它时,它只转向正好 90º。当我再次单击时,它不会转到 180º、270º 并在第四次单击时返回到 0º。
public Image image;
public void WheelClicker()
{
image.gameObject.transform.DORotate(new Vector3(0, 0, image.gameObject.transform.rotation.z + 90), 1);
}
最佳答案
transform.rotation
是一个 Quaternion
值(value)!除非您确切地知道自己在做什么,否则永远不要触摸它的各个组件(x
、y
、z
、w
). transform.rotation.z
的值不是您正在寻找的值!
您应该使用 transform.eulerAngles
public Image image;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) WheelClicker();
}
public void WheelClicker()
{
// always prevent concurrent animations
if (DOTween.IsTweening(image.transform)) return;
image.transform.DORotate(image.transform.eulerAngles + new Vector3(0, 0, 90), 1);
}
关于c# - Unity 每次点击都会增加 90º,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57469572/