My randomly generated mesh is not rendering for some reason Below is the script and a picture of the problem
[2]:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class MeshGenerator : MonoBehaviour
{
Mesh mesh;
Vector3[] verts;
int[] triangles;
public int xSize = 20;
public int zSize = 20;
private void Start()
{
mesh = new Mesh();
GetComponent<MeshFilter>();
CreateShape();
UpdateMesh();
}
void CreateShape()
{
verts = new Vector3[(xSize + 1) * (zSize + 1)];
int i = 0;
for (int z = 0; z <= zSize; z++)
{
for (int x = 0; x <= xSize; x++)
{
verts *= new Vector3(x, 0, z);*
i++;
}
}
triangles = new int[xSize * zSize * 6];
int vert = 0;
int tris = 0;
for (int z = 0; z < zSize; z++)
{
for (int x = 0; x < xSize; x++)
{
triangles[tris + 0] = vert + 0;
triangles[tris + 1] = vert + xSize + 1;
triangles[tris + 2] = vert + 1;
triangles[tris + 3] = vert + 1;
triangles[tris + 4] = vert + xSize + 1;
triangles[tris + 5] = vert + xSize + 2;
vert++;
tris += 6;
}
vert++;
}
}
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = verts;
mesh.triangles = triangles;
mesh.RecalculateNormals();
}
private void OnDrawGizmos()
{
if(verts == null)
{
return;
}
for (int i = 0; i < verts.Length; i++)
{
Gizmos.DrawSphere(verts*, .1f);*
}
}
}