unity3d-Code Implementation Gameobject creation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.