unity 圆环算法---排列成圆环

 private int number; //子物体个数
    private float angle = 0;//角度
    public float r = 1;

    void Start()
    {
        number = this.transform.childCount;

        Debug.Log("子物体数量:" + number);
        Debug.Log("角度:" + 360 / number);

        for (int i = 0; i < number; i++)
        {
            float hudu = (angle / 180) * Mathf.PI;
            float xx = r * Mathf.Cos(hudu);
            float zz = r * Mathf.Sin(hudu);

            this.transform.GetChild(i).localPosition = new Vector3(xx, 0, zz);

            //角度增加
            angle += 360 / number;

        }

unity 圆环算法---排列成圆环_第1张图片

红色为圆心

 

你可能感兴趣的:(unity)