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