實現
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?