实现
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
textureCoord = hit.textureCoord;
textureCoord.x *= textureMat.width;
textureCoord.y *= textureMat.height;
textureColor = textureMat.GetPixel(Mathf.FloorToInt(textureCoord.x), Mathf.FloorToInt(textureCoord.y));
}
*贴图和物体的Read/Write Enabled 都需处于开启状态,贴图的Use Crunch Compression 需处于关闭状态。
效果
*右侧为世界中的3d 物体,左侧为Canvas 上的Image