Unity2D之检测三点处于一条直线

     Vector2Int a = new Vector2Int(2, 1);
        Vector2Int b = new Vector2Int(2, 1);
        Vector2Int c = new Vector2Int(5, 1);

        int k1, k2, k3;

        //x轴
        if(a.x != b.x && b.x != c.x && c.x != a.x)
        {

            k1 = (b.y - a.y) / (b.x - a.x);
            k2 = (c.y - b.y) / (c.x - b.x);
            k3 = (c.y - a.y) / (c.x - a.x);

            if (k1 == k2 && k2 == k3)
            {
                Debug.Log("Yes");
            }
            else
            {
                Debug.Log("No");
            }

        }
        else if (a.x == b.x && b.x == c.x)
        {
            Debug.Log("Yes");
        }
        else
        {
            if (a.y == b.y && b.y == c.y)
                Debug.Log("Yes");
            else
                Debug.Log("No");
           
        }

  

 

posted on 2020-10-13 10:07  jiahuafu  阅读(194)  评论(0编辑  收藏  举报

导航