Search Unity

How I instantiate specific decals to specific textures?

Discussion in 'Scripting' started by the_Bad_Brad, Nov 16, 2018.

  1. the_Bad_Brad

    the_Bad_Brad

    Joined:
    Nov 2, 2014
    Posts:
    278
    For example our mesh has 4 materials, wood, metal, brick and plaster. Now how do I instantiate their respective bullet hit marks?

    I have one temporary solution, overlay a plane on each with tags named after the surface it is laid on.

    I cannot use tags and layers since it is only one mesh like a building for example.

    I have one idea like using rgb vertex colors but I do not know how to implement it. I have vertex painted the mesh.

    Any help is appreciated
     
    Last edited: Nov 16, 2018
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    How are the materials mapped to the mesh?
    Just through UV coordinates? If so it might be tricky, but still possible.

    Make a tiny texture that's (for example) pure red for metal, pure blue for brick, ...
    On hit look up the UV coords (should be given to you by a raycast automatically already), then just look at the pixel color of your lookup texture and you know what material type was hit.

    Remember to save the texture uncompressed