Prior to knowing that a method is more complex is to take out the map, similar to the top to bottom from left to right to traverse a graph, to remove pixels to change the pixel point. Today in the election of the Big Brother to see the following method, feel very simple, the principle should be the same bar.
Official documents:
Https://docs.unity3d.com/ScriptReference/RaycastHit-textureCoord.html
Enclosed in Chinese version:
Http://www.manew.com/youxizz/2393.html
Create a new script to copy the code from the link above, remember to change the name. Hang the script on top of the scene's main camera:
In the scene of a random object component remember mesh Collider convex do not tick ps:unity province point convex explanation:
(The convex didn't know much about efficiency or anything.) https://www.zhihu.com/question/40575282)
Next, notice whether the settings for this map are writable:
Set up the apply. Run the game and you're done:
Only the grass sheep look and draw a grass sheep. After you close the game, you can also see that the decal file changed:
Above.
It's okay. There are many good things to do in the official documentation.
can also be changed to try to try what effect-
Color[] C = Tex. Getpixels (0055); Tex. SetPixels ((int) pixeluv.x, (int) PIXELUV.Y,5,5, C);
Source above the link on it, because not particularly many at the end of a copy, hand lazy direct stick:
//Write black pixels onto the gameobject is located//By the script. The script is attached to the camera.//determine where the collider hits and modify the texture at this point.////Note that the Meshcollider on the gameobject must has convex turned off. This allows//concave gameobjects to being included in collision in this example.////Also to allow the texture to being updated by mouse button clicks it must has the Read/write//The Enabled option set to TRUE on its advanced import settings.usingUnityengine;usingSystem.Collections; Public classexampleclass:monobehaviour{ PublicCamera Cam; voidStart () {Cam= getcomponent<camera>(); } voidUpdate () {if(! Input.getmousebutton (0)) return; Raycasthit hit; if(! Physics.raycast (Cam. Screenpointtoray (input.mouseposition), outHit )) return; Renderer rend= hit.transform.getcomponent<renderer>(); Meshcollider Meshcollider= Hit.collider asMeshcollider; if(rend = =NULL|| Rend.sharedmaterial = =NULL|| Rend.sharedMaterial.mainTexture = =NULL|| Meshcollider = =NULL) return; Texture2d Tex= Rend.material.mainTexture astexture2d; Vector2 Pixeluv=Hit.texturecoord; pixeluv.x*=Tex.width; Pixeluv.y*=Tex.height; Tex. SetPixel ((int) pixeluv.x, (int) pixeluv.y, Color.Black); Tex. Apply (); }}
Unity a simple way to implement a bullet