Webgl cannot get textureCoord correctly

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.


Does anybody has any idea?
Thx for your help.

Setting the mesh collider to read/write true in the model import settings seems to fix this.