Rotate sprite around pivot with finger drag

2019-09-02 04:45发布

I am rotating a clock hand around clock center, and I am using:

Vector3 dir = mouseClickPos - transform.position;
float angle = Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

And it is working like a charm. But I need it not to go smooth but to skip around 15 degrees. How can I do that?

1条回答
何必那么认真
2楼-- · 2019-09-02 05:31

Try

angle=Mathf.Round(angle/15f)*15f

(sorry for the wrong math at first, need coffee)

查看更多
登录 后发表回答