Unity script--08 Adding components and modifying components

Source: Internet
Author: User

Study Notes for beginners, please correct me if you have any mistakes. The number is also please point out, thank you.

Common components are: physical class, Grid class, particle class, etc.

Adding components using the AddComponent () method

Remove components using the Object.destroy () method parameter for a game object or game component that needs to be deleted

Instance:

Create an empty cube object, add a render component, and after running the game, click the Add Color button or the Add Map button in the game view to add color to the cube object

usingUnityengine;usingSystem.Collections; Public classC_3_5_3:monobehaviour { PublicTexture Texture; PrivateGameobject obj; PrivateRenderer render; voidStart () {//get the Game objectobj = Gameobject.find ("Cube"); //gets the renderer for the objectRender = obj. Getcomponent<renderer>(); }    voidOngui () {if(Guilayout.button ("Add Color", Guilayout.width ( -), Guilayout.height ( -)))        {            //modify render color to redRender.material.color =color.red; }        if(Guilayout.button ("Add a decal", Guilayout.width ( -), Guilayout.height ( -)))        {            //Add a component mapRender.material.mainTexture =texture; }    }}

Render.meterial refers to the material of the current script binding object and assigns it directly to the modified object material

Render.material.color is the color of the material

Render.material.mainTexture as the material's primary map

Unity script--08 Adding components and modifying components

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.