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

相关推荐
地狱为王13 小时前
Unity使用AnimeGANv3实现动漫风格化效果(二)
unity·游戏引擎
fcm1913 小时前
unity之线框模式
unity·游戏引擎
unity工具人13 小时前
unity DoTween DoPath设置物体按照指定轨迹运动
unity·游戏引擎
程序猿阿伟13 小时前
《风格锚点+动态适配:Unity跨设备渲染的核心逻辑》
unity·游戏引擎
倚剑仙1 天前
Unity-WebGL开发——用IIS(Internet Information Services)部署webGL工程
unity·游戏引擎·webgl
baldr_43961 天前
关于光照探针的实验和疑问
unity
作孽就得先起床1 天前
c#调Lua返回个字符串
unity·c#·lua·xlua
井队Tell1 天前
打造高清3D虚拟世界|零基础学习Unity HDRP高清渲染管线(第十天)
学习·3d·unity
Python私教2 天前
Unity 游戏开发「工业化级」学习路线 2025 版
学习·unity·游戏引擎
于小汐在咯2 天前
【Unity每日一记】Unity物理引擎:刚体与碰撞体详解
unity·游戏引擎