您的位置:首页 > 其它

Untiy3D笔记之番外篇——判断手指滑动方向之角度篇

2015-09-13 20:25 344 查看
float x = Input.GetAxis("Mouse X") - Oposition.x;
float y = Input.GetAxis("Mouse Y") - Oposition.y;
float tanxy = x / y;
float sinxy = y / (x * x + y * y);
zhongdian = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
Debug.DrawLine(Oposition, zhongdian, Color.red);
if (y > 0 && sinxy > Mathf.Sin(Mathf.PI / 4) && sinxy < Mathf.Sin(Mathf.PI * 3 / 4))
{
Debug.Log("上");
}
else if (y < 0 && sinxy < Mathf.Sin(Mathf.PI * 5 / 4) && sinxy > Mathf.Sin(Mathf.PI * 7 / 4))
{
Debug.Log("下");
}
else if (x > 0 && x / y > -1 && x / y < 1)
{
Debug.Log("右");
}
else if (x < 0 && x / y > -1 && x / y < 1)
{
Debug.Log("左");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: