I have a box collider attached to a body. Now whenever a ball comes in contact this body. I want to produce a particle effect that has the color of the point of contact on the box body. Note that am changing the texture of the box body at run time and the color I need should be based on the texture at the time of collision(ie the color of the texture, at the point of collision).
No code since I don’t have Unity running, but an idea that should work:
Take a contact point _cp (collision.contacts returns a ContactPoint … pick one)
Do a raycast from _cp.point+_cp.normal to _cp.point
The RaycastHit object gives you the object’s renderer (and through that the Texture2D) and the UV coordinate (hit.textureCoord).
Now you can simply use texture.GetPixel(texCoord.x * texture.width, texCoord.y * texture.height) to get the color.
Hope this makes sense. For the raycasting part, you can have a look at that example: http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-textureCoord.html