Unity 之圆环算法

先上代码

http://www.cnblogs.com/wuzhang/p/wuzhang20150410.html

using UnityEngine;
public class Circle : MonoBehaviour
{
    public GameObject circleModel;
    //旋转改变的角度
    public int changeAngle = 1;
    //旋转一周需要的预制物体个数
    private int count;
    private float angle = 0;
    public float r = 5;
    void Start()
    {
        if (circleModel == null)
            circleModel = GameObject.CreatePrimitive(PrimitiveType.Cube);
        count = (int)360 / changeAngle;
        for (int i = 0; i < count; i++)
        {
            Vector3 center = circleModel.transform.position;
            GameObject cube = (GameObject)Instantiate(circleModel);
            float hudu = (angle / 180) * Mathf.PI;
            float xx = center.x + r * Mathf.Cos(hudu);
            float yy = center.y + r * Mathf.Sin(hudu);
            cube.transform.position = new Vector3(xx, yy, 0);
            cube.transform.LookAt(center);
            angle += changeAngle;
        }
    }
}
**上图**

Sphere圆环
Unity 之圆环算法_第1张图片
Capsule圆环
Unity 之圆环算法_第2张图片
Cube圆环
Unity 之圆环算法_第3张图片

你可能感兴趣的:(Unity3D_转载)