Unity以物体中心为圆心的圆形检测

小菜鸟 2021-11-19 PM 125℃ 0条
 /// <summary>
    /// 圆形检测
    /// </summary>
    /// <param name="player"></param>
    /// <returns></returns>
    List<Vector3> angle(GameObject player)
    {
        List<Vector3> angle = new List<Vector3>();
        float Start_angle = player.transform.eulerAngles.z + 90;//检测射线开始的角度
        for (int i = 0; i < 21; i++) //21*18+18  18°一条线,首尾共21条
        {
            float hudu = (Start_angle * Mathf.PI) / 180;
            float xx = player.transform.position.x + [物体的x方向的长一半,也就是半径]* Mathf.Cos(hudu);
            float yy = player.transform.position.y + [物体的y方向的长的一半,也就是半径] * Mathf.Sin(hudu);
            Debug.DrawLine(player.transform.position, new Vector3(xx, yy, 0), Color.red);
            angle.Add(new Vector3(xx, yy, 0));//添加需要检测的点
            Start_angle -= 18;
        }
        return angle;
    }
标签: none

非特殊说明,本博所有文章均为博主原创。

评论啦~