OK, the above has created a mesh, we use Main.cs to code to create Gameobject.
It is generally shader attached to the material material attached to the mesh.
But mesh we have generated, it is very difficult to get the results generated by the code, we have to drag into the panel, and then drag into the panel gameobject to Main.cs
OK, look at Main.cs's main code.
Using unityengine;using system.collections;using Unityeditor;public class Main:monobehaviour {//Create Simplemesh after the value instantiated Drag into public gameobject meshobject;//with this for initializationvoid awake () {Createmesh ();} Create Meshobject void Createmesh () {Gameobject Simplemesh = new Gameobject (); The definition object is named water simplemesh.name = "water"; Add Meshfilter simplemesh.addcomponent<meshfilter> (); Add Meshrenderer simplemesh.addcomponent<meshrenderer> (); Assigns the newly created Simplemesh to the new Gameobject simplemesh.getcomponent<meshfilter> (). Mesh = Meshobject.getcomponent<mesh Filter> (). Mesh; Create Shader for Vertexcolor Material Material simplematerial = new Material (Shader.find ("Custom/vertexcolor")); Join Simplematerial simplemesh.getcomponent<meshrenderer> (). material = simplematerial; Add script simplemesh.addcomponent<waterscript> (); }}
The results obtained are
This figure only shows that this gameobject material, the script is all ~ ~
unity3d-Code Implementation Gameobject creation