Quantcast
Channel: Latest Questions by Monko
Viewing all articles
Browse latest Browse all 34

Unity isn't reading the mesh I created

$
0
0
In my game, I am proceduraly drawing a mesh. I know how to draw the mesh, so now Im putting it into a function so I can call the function later. Here is my code so far: function Start(){ var block : GameObject = new GameObject("Block"); var mesh : Mesh = new Mesh (); var meshFilter = block.AddComponent(MeshFilter); block.AddComponent(MeshRenderer); block.renderer.material = Resources.Load("VoxelMaterial"); DrawTheMesh(); } function DrawTheMesh() { var vertices = new Vector3[4]; var triangles = new int[6]; vertices[0] = Vector3(0,0,0); vertices[1] = Vector3(0,0,1); vertices[2] = Vector3(1,0,1); vertices[3] = Vector3(1,0,0); triangles = [0,1,2,0,2,3]; mesh.vertices = vertices; mesh.triangles = triangles; var uvs = new Vector2[mesh.vertices.length]; for (var i=0; i < uvs.Length; i+=1) { uvs[i] = Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } } I know this code works just fine, because Ive drawn a shape with it before. But when I put it into a function called DrawTheMesh, it gives an error saying "unknown identifier: "mesh" ". Which doesn't make sense, since I clearly defined it at the very beggining during the Start function. Does anyone know why its doing this?

Viewing all articles
Browse latest Browse all 34

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>