统一 - 反向变换欧拉角,因此顺时针计数吗?
我正在做某种鸡蛋计时器的东西...您可以在其中旋转时钟输入分钟。但是,transform.eulerangles的解决方法是错误的:
但是我需要这样做:
这样我就可以通过将数字除以6来轻松地获得我的分钟...但是我不能以某种方式弄清楚,如何将其翻转。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class Test3 : MonoBehaviour
{
[SerializeField] RectTransform rectTransform;
int[] snapValues = new int[13]{0,30,60,90,120,150,180,210,240,270,300,330,360};
public void Drag()
{
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(rectTransform.anchoredPosition);
var angle = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);
var nearest = snapValues.OrderBy(x => Mathf.Abs(x - transform.eulerAngles.z)).First();
print(transform.eulerAngles.z);
}
}
I'm making some sort of a egg timer thing... where you can input your minutes by rotating the clock. transform.Eulerangles however goes the wrong way around:
But I need it to go this way around:
So I can can easily get my minutes by dividing the numbers by 6... but I can somehow not figure it out, how to flip it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class Test3 : MonoBehaviour
{
[SerializeField] RectTransform rectTransform;
int[] snapValues = new int[13]{0,30,60,90,120,150,180,210,240,270,300,330,360};
public void Drag()
{
var dir = Input.mousePosition - Camera.main.WorldToScreenPoint(rectTransform.anchoredPosition);
var angle = Mathf.Atan2(dir.x, dir.y) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, -Vector3.forward);
var nearest = snapValues.OrderBy(x => Mathf.Abs(x - transform.eulerAngles.z)).First();
print(transform.eulerAngles.z);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要翻转结果(即360 = 0,180 = 180,0 = 360),您可以从360中减去它:
To flip the result (i.e. 360 = 0, 180 = 180, 0 = 360), you can just subtract it from 360: