I am trying to create a circle out of vertices based on certain parameters like subdivision or radius. This time I have been avoiding using tutorials as a crutch as I haven't been able to learn C# by not actually working with it. I finished this bit of code and got stuck on the console errors because I am a beginner with troubleshooting. Would any of you be able to help me understand what they mean?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class circleVerts : MonoBehaviour
{
private void Update () {
Generate();
}
private void Generate () {
GetComponent<MeshFilter>().mesh = mesh = new Mesh();
mesh.name = "Procedural Circle";
public int radiusR = 2;
public float nTimes = 1.0f; //# of subdivisions, cannot equal 0
public int numPlayers = 4;
public float thetaT = (Mathf.Pow(2, nTimes) / Mathf.Pow(numPlayers, nTimes)) * Mathf.PI;
vertices = new Vector3[(Mathf.Pow(2, nTimes - 1)) + 2];
for (int i = 0; i <= vertices.length; i++)
{
float x = Mathf.Cos(thetaT) * radiusR;
float y = Mathf.Sin(thetaT) * radiusR;
vertices[0] = new Vector3(0,0,0); //setting origin
vertices[1] = new Vector3(radiusR, 0, 0); //first vert is located at x-radius
vertices[i] = new Vector3(x, 0, y);
Gizmos.DrawSphere(vertices[i].position, 1);
}
mesh.vertices = vertices;
}
}
