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

相关推荐
不绝1911 小时前
Unity入门 :场景叠加/预制体资源包/脚本资源/生命周期函数/Inspector页面
unity·游戏引擎
在路上看风景2 小时前
20. 资源和脚本的绑定关系
unity
yj爆裂鼓手4 小时前
unity对象池
unity·c#
在路上看风景5 小时前
3.7 SRP Batcher
unity
快乐觉主吖5 小时前
Unity方便修改产品名和包名的小工具
unity·游戏引擎
JIes__17 小时前
Unity(二)——MonoBehavior中的重要内容
unity·游戏引擎
4Forsee1 天前
【增强现实】快速上手 Vuforia Unity Android AR 应用开发
android·unity·ar
两水先木示1 天前
【Unity】对指定物体进行描边——模板测试法
unity·游戏引擎·shader·外描边
Miss_SQ1 天前
实现Unity录音、百度云语音转文字
unity·语音识别
CreasyChan1 天前
unity 对象池实测可用
unity·c#