Unity3d用Gizmos画一个圆圈

public int VertexCount = 50;//定义圆圈边定点数量,数值越高越平滑
public float Radius = 1;//圆形半径
public Vector3 Offset;//圆圈位移

void OnDrawGizmos()
    {
        float deltaTheta = (2f * Mathf.PI) / VertexCount;
        float theta = 0f;
        Vector3 oldPos = transform.position;
        for (int i = 0; i < VertexCount + 1; i++)
        {
            Vector3 pos = new Vector3(Radius * Mathf.Cos(theta), Radius * Mathf.Sin(theta), 0f);
            Gizmos.DrawLine(oldPos, transform.position + pos + Offset);
            Gizmos.color = Color.red;
            oldPos = transform.position + pos + Offset;

            theta += deltaTheta;
        }
    }

你可能感兴趣的:(Unity3D)