I’m working on some simple shooter mechanics but ran into this dilemma.
Working on the bullet hit effect, i would like the resulting particle color to be based on what you hit.
Is there a way to get the texture color of the UV position of the part of the mesh my bullet ray intersects?
Although i have already planned a way to do this, that i know will work.
I realized if what i’m asking is possible it would be a lot more dynamic and less setup-intensive.
Well, if the object has a MeshCollider the RaycastHit will contain the UV position of the point you’ve hit. Then you can use GetPixelBilinear of the texture of the object with your UV coordinate to get the blended color of the given point.
Though keep in mind that this does not work with skinned meshes as a MeshCollider is not skinned at all. If you have a skinned mesh you could try using BakeMesh, create a temporary mesh collider with the snapshot mesh and work out the color in the same way. Though this might be a bit too heavy.