Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. private void buildMesh()
  2.     {
  3.         Vector3[] vertices = new Vector3[4]; // For each corner
  4.         Vector3[] normals = new Vector3[4]; //  For lighting iirc
  5.         int[] tris = new int[6]; // The vertices that make a  triangle
  6.  
  7.         Mesh mesh = new Mesh();
  8.         MeshRenderer  meshRender = GetComponent<MeshRenderer>();
  9.         MeshFilter meshFilter = GetComponent<MeshFilter>();
  10.  
  11.         //If Mesh renderer  is null gtfo
  12.         if(meshRender == null)
  13.         {
  14.             //We fucked up mayne
  15.             return;
  16.         }
  17.  
  18.         // if Mesh Filter  is null gtfo
  19.         if(meshFilter == null)
  20.         {
  21.             //We fucked up mayne
  22.             return;
  23.         }
  24.  
  25.         vertices[0] = new Vector3(0, 0 , 0); // Left top vert
  26.         vertices[1] = new Vector3(1, 0, 0); // Right top vert
  27.         vertices[2] = new Vector3(0, 0, -1); // left bottom vert
  28.         vertices[3] = new Vector3(1, 0, -1); // right bottom vert
  29.  
  30.         //Left Triangle
  31.         tris[0] = 0; // vert 0
  32.         tris[1] = 3; // vert 3
  33.         tris[2] = 2; // vert 2
  34.  
  35.  
  36.         //Right triangle
  37.         tris[3] = 0; // vert 0
  38.         tris[4] = 1; // vert 1
  39.         tris[5] = 3; // vert 3
  40.  
  41.         //Iirc light should happen on top
  42.         normals[0] = Vector3.up;
  43.         normals[1] = Vector3.up;
  44.         normals[2] = Vector3.up;
  45.         normals[3] = Vector3.up;
  46.  
  47.  
  48.         mesh.vertices = vertices; // Set the mesh's vertices to what we made
  49.         mesh.triangles = tris; // Set the triangles to "       ".
  50.         mesh.normals = normals; // set the normals  to "    ".
  51.  
  52.         meshFilter.mesh = mesh; // Set the mesh filter's mesh to the mesh we made
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement