I’m trying to use textureCoord to get the texture’s pixel color at object’s position.
Below is the sample code.
Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;
Vector2 tiling = rend.material.mainTextureScale;
Color color = tex.GetPixel(Mathf.FloorToInt(pixelUV.x * tiling.x), Mathf.FloorToInt(pixelUV.y * tiling.y));
This works fine in Unity editor, can get correct textureCoord.
But once it build into webgl, textureCoord will always return (0, 0).
I’ve already turned off Convex option and use MeshCollider.
[175228-擷取.png|175228]
Does anybody has any idea?
Thx for your help.