Create a rectangular grid of two triangular compositions:
Gameobject obj=NewGameobject (); Meshrenderer Meshrenderer=obj. Addcomponent<meshrenderer>(); Meshfilter Meshfilter=obj. Addcomponent<meshfilter>();//Render MaterialMeshrenderer.material=NewMaterial (Shader.find ("Sprites/default"));//create a material from a bagMeshrenderer.material.maintexture= (Texture) resources.load ("a");//"A" 2d texture under the Resources folderMesh Mesh=NewMesh (); Meshfilter.mesh=mesh;mesh.vertices=Newvector3[]{NewVector3 (0,0),NewVector3 (3,0),NewVector3 (0,3),NewVector3 (3,3)};//Mesh vertices//UV mapping coordinates, length and vertex number leader degree consistent, value 0~1mesh.uv=Newvector2[]{NewVector2 (0,0),NewVector2 (1,0),NewVector2 (0,1),NewVector2 (1,1) };//the vertex rendering order of the triangles, each of which corresponds to each vertex in the vertex array, the length is: the number of triangles, when a triangle is less filled, the triangle is not rendered, the length must be a multiple of 3mesh.triangles=New int[]{ 0,1,2, 1,2,3};
Use of Unity mesh (GRID)