Demo 1
Construct a mesh that contains only a single triangle and texture coordinates
usingUnityengine;usingSystem.Collections; Public classmeshtest:monobehaviour{voidStart () {meshfilter MF= getcomponent<meshfilter>(); Mesh Mesh=NewMesh (); Mf.mesh=mesh; Mesh.vertices=Newvector3[3] {NewVector3 (0,0,0),NewVector3 (0,1,0),NewVector3 (1,1,0) }; Mesh.uv=Newvector2[3] {NewVector2 (0,0),NewVector2 (0,1),NewVector2 (1,1) }; Mesh.triangles=New int[3] {0,1,2 }; }}
You can see only a single triangle
As you can see from the right, there are 1 triangles, 3 vertices
Demo2
Construct a grid of two triangles and texture coordinates
usingUnityengine;usingSystem.Collections; Public classmymesh:monobehaviour{voidStart () {meshfilter MF= getcomponent<meshfilter>(); Mesh Mesh=NewMesh (); Mf.mesh=mesh; //vertex [determines the scale of the image drawn out]Mesh.vertices =Newvector3[4] {NewVector3 (0,0,0),NewVector3 (1,0,0),NewVector3 (0,1,0),NewVector3 (1,1,0) }; //the order of the Triangle Vertex index [multiples of 3]Mesh.triangles =New int[6] {0,2,1,2,3,1 }; //NormalMesh.normals =Newvector3[4] {NewVector3 (0,0, -1),NewVector3 (0,0, -1),NewVector3 (0,0, -1),NewVector3 (0,0, -1), }; //UV Texture CoordinatesMESH.UV =Newvector2[4] {NewVector2 (0,0),NewVector2 (1,0),NewVector2 (0,1),NewVector2 (1,1) }; }}
As you can see from the right, there are 2 triangles, 4 vertices
The triangle vertex order is set differently, and the effect drawn is not the same (mesh.triangles = new Int[6] {0, 2, 1, 0, 3, 1};)
Graphic
Steps
1. Create an empty Gameobject, bind the mesh filter and mesh renderer components
2, create a material, drag a picture in, modify shader for transparent shader
3, the 2 created by the material assigned to 1 created Gameobject mesh renderer under the MATERIASL
4, this time by default in the scene is not see this gameobject rendering
5. Create script MeshTest.cs code such as Demo1, bind on Gameobject, run view effect
6. Create script MyMesh.cs code such as Demo2, bind on Gameobject, run view effect
Other methods
Create a quad that you don't need to run in the scene to see
Report
Links to some other methods
Unity3d Research Institute and the two trajectory points according to the dynamics of the drawing surface detailed (20) http://www.xuanyusong.com/archives/780
Use of meshrenderer in <unity3d>unity3d http://blog.csdn.net/zuoyamin/article/details/9287507
[Unity3d Study] Mesh create triangles, rectangles http://blog.gamerisker.com/archives/494.html
Triangular mesh (Triangle mesh) http://lib.yoekey.com/?p=120
Unity C # Programming stars (i) http://unity3d.9tech.cn/news/2014/0324/40085.html
C # code to create a 3D model