Unity 获取鼠标点击位置物体贴图颜色

实现

复制代码
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

相关推荐
微:xsooop9 小时前
iOS 上架4.3a 审核4.3a 被拒4.3a 【灾难来袭】
flutter·unity·ios·uniapp
微光守望者9 小时前
Unity ScriptableObject详解:优化游戏架构的强大工具
unity·游戏引擎
jtymyxmz10 小时前
《Unity Shader》10.2.2 玻璃效果
unity·游戏引擎
zxc24460393413 小时前
gpu instancer crowd 动画使用方式
unity
C MIKE14 小时前
unity资源下载
unity
Avalon71214 小时前
Unity中自定义协程的实现
游戏·unity·c#·游戏引擎
jtymyxmz16 小时前
《Unity shader》10.1.5 菲涅尔反射
unity·游戏引擎
老朱佩琪!17 小时前
Unity文字排版错位问题
经验分享·unity·游戏引擎
jtymyxmz17 小时前
《Unity Shader》9.4.3 使用帧调试器查看阴影绘制过程
unity·游戏引擎
jtymyxmz17 小时前
《Unity Shader》10.3.1 在Unity中实现简单的程序纹理
unity·游戏引擎