美文网首页
unity 多个物体模拟中心点(找到几个物体的中心点)

unity 多个物体模拟中心点(找到几个物体的中心点)

作者: WOTTOW | 来源:发表于2020-09-20 10:54 被阅读0次
    public Vector3 WholeFloorCenter(Transform transform_)
    {
        Transform parent = transform_;
        Vector3 center = Vector3.zero;
        if (parent.childCount > 0)
        {
            for (int i = 0; i < parent.childCount; i++)
            {
                center += parent.GetChild(i).position;
            }
            center /= parent.childCount;

            return center;
        }
        else
        {
            return Vector3.zero;
        }
    }

相关文章

网友评论

      本文标题:unity 多个物体模拟中心点(找到几个物体的中心点)

      本文链接:https://www.haomeiwen.com/subject/syvuyktx.html