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

来源:互联网 发布:北京java培训学校 编辑:程序博客网 时间:2024/05/21 16:56
        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("左");        }

0 0