Adding decals to a object

how do i add decals to a object? say i want to render bullet marks on a cube or wall.

The simplest way to achieve this would be to Instantiate a bullet-hole object at the point at which your bullet raycast hits the wall, and use the wall's normal for the object's rotation.

Something like this:

var hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
Instantiate(bulletHole, hit.point, hitRotation);

However if you allow the creation of an unlimited number of bullet holes, this method might quickly start affecting performance. There are a number of ways of creating a more optimised 'decal' system, such as re-using a pool of decal objects.

currently decal rendering is not supported in unity. vote for this in feedback http://feedback.unity3d.com/pages/15792-unity however you can easily draw a texute on another with getpixels and setpixels functions of Texture2D class. you can draw bullet texture easily on the wall. you should not use the sharedmaterial and should use the material property to get textures. if you use sharedmaterial the real asset file and all other gameobjects using the texture/material will change. you should get the UV cords of a raycast from Raycasthit object in raycasts. in collisions and functions like OnTriggerEnter or ... you can cast a ray from the bullet's position and in it's movement direction and see where it will collide to the other collider. you should disable the raycast for the bullet itself

I wrote my decal script into the FPS tutorial mating gun script
here it is

add this to the variables

var BulletTexture : GameObject;

add this to the hit particles section

clone = Instantiate(BulletTexture, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
Destroy(clone.gameObject, 5);
clone.transform.parent = hit.transform;

it will parent the decal object with whatever it hits then deletes it after 5 seconds

Dj

I've tried a lot to get this to work but I can't figure it out. Where do I put the code? In the gun or the bullet object? I tried with putting it in the bullet and what I got was a string of bullethole objects on the ground between me and the direction I was shooting. I have no idea what I'm doing.