Mesh needs to be created in code.
Using unityengine;using system.collections;using Unityeditor;public class Createmesh:monobehaviour {//Vertex collection Priva Te vector3[] vertices = new vector3[constnumber.pointsum]; Triangle index Altogether (constnumber.xlength-1) * (constnumber.ylength-1) of rectangles, each rectangle 6 points private int[] triangles = new INT[6 * (Con STNUMBER.XLENGTH-1) * (constnumber.ylength-1)]; Private color[] Colors = new color[constnumber.pointsum];//Use this for initializationvoid Start () {Createme Shfun ();} public void Createmeshfun () {Mesh mesh = new Mesh (); Mesh = Createmeshobject (); Assetdatabase.createasset (Mesh, "assets/" + "pollutant" + ". Asset"); Print the path of the new resource//Debug.Log (Assetdatabase.getassetpath (mesh)); } Private Mesh Createmeshobject () {Mesh mesh = new mesh (); Initialize vertex position initvertexpos (); Triangle index inittriangles (); Initialize color initcolors (); Vertex assignment mesh.vertices = vertices;Index assignment mesh.triangles = triangles; To vertex coloring mesh.colors = colors; Recalculates the normal mesh of the mesh. Recalculatenormals (); return mesh; }//initialize vertex position private void Initvertexpos () {int currentindex = 0; for (int i = 0, i < constnumber.ylength; i++) {for (int j = 0; J < Constnumber.xlength; J + +) {Vertices[currentindex] = new Vector3 (j, 0, I); currentindex++; }}}//initialize triangle index private void Inittriangles () {//Represents the current index value of the Triangl array, each place a value in the array, Currentindex increases by 1 int currentindex = 0; for (int i = 0, i < constnumber.ylength-1; i++) {for (int j = 0; J < Constnumber.xlength-1; j + +) {//Draw the upper left corner triangle triangles[currentindex++] = (i + 0) * Constnumber.xlength + ( j + 0); triangles[currentindex++] = (i + 1) * Constnumber.xlength + (j + 0); triangles[currentindex++] = (i + 1) * Constnumber.xlength + (j + 1); Draw clockwise triangle triangles[currentindex++] = (i + 0) * Constnumber.xlength + (j + 0); triangles[currentindex++] = (i + 1) * Constnumber.xlength + (j + 1); triangles[currentindex++] = (i + 0) * Constnumber.xlength + (j + 1); }}}//Initialize color private void Initcolors () {for (int i = 0; i < constnumber.pointsum; i++) {Color color = new Color (0, 0, 0); Colors[i] = color; } }}
Will grow into a rectangular mesh with a xlength width of ylength
OK, drag in, hierarchy panel, get Gameobject
Mesh creation is complete.
Unity3d-mesh Create