/// <summary>
        /// 从列表points中获取距离targetPoint最近的坐标
        /// </summary>
        /// <param name="points"></param>
        /// <param name="targetPoint"></param>
        /// <returns></returns>
        public Vector3 FindClosestPoint(List<Vector3> points, Vector3 targetPoint)
        {
            Vector3 closestPoint = Vector3.zero;
            float closestDistance = Mathf.Infinity;

            foreach (Vector3 point in points)
            {
                float distance = Vector3.Distance(point, targetPoint);

                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closestPoint = point;
                }
            }

            return closestPoint;
        }
/// <summary>
        /// 获取_angleList中最接近angle的角度
        /// </summary>
        /// <param name="_angleList">所有正对按钮时的角度</param>
        /// <param name="_angle">rot当前的角度</param>
        /// <returns></returns>
        public float Closest(List<float> _angleList, float _angle)
        {
            float closest = _angleList[0];
            float difference = Mathf.Abs(closest - _angle);

            foreach (float item in _angleList)
            {
                float currentDifference = Mathf.Abs(item - _angle);
                if (currentDifference < difference)
                {
                    closest = item;
                    difference = currentDifference;
                }
            }

            return closest;
        }

 

posted on 2024-07-03 17:29  凌落成迷  阅读(19)  评论(0编辑  收藏  举报