}
public Mesh CreateArcMeshForUnit(Transform unit, float arc, float length, int numberOfVerticesInArc = 100) {
return CreateArcMesh(unit.localPosition, unit.forward, arc, length, numberOfVerticesInArc, Vector3.up);
}
public Mesh CreateArcMesh(Vector3 origin, Vector3 direction, float arc, float length, int numberOfVerticesInArc, Vector3 rotationAxis) {
Mesh mesh = new ();
int n = numberOfVerticesInArc + 1;
float arcStep = arc / (n-2);
float currentDegrees = -arc / 2;
Vector3[] vertices = new Vector3[n];
vertices[0] = origin;
for (int i = 1; i < n; i++) {
vertices[i] = Quaternion.AngleAxis(currentDegrees, rotationAxis) * direction * length;
//Debug.Log($"Current Degrees: {currentDegrees} -> {vertices[i]}");
currentDegrees+= arcStep;
}
mesh.vertices = vertices;
int[] tris = new int[(n-2) * 3];
for (int i = 0; i < n - 2; i++) {
tris[i * 3] = 0;
tris[i * 3 + 1] = i + 1;
tris[i * 3 + 2] = i + 2;
}
mesh.triangles = tris;
Vector3[] normals = new Vector3[n];
for (int i = 0; i < n; i++) {
normals[i] = rotationAxis;
}
mesh.normals = normals;
return mesh;