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

相关推荐
龚子亦20 小时前
【Unity开发】热更新学习——HybridCLR框架
学习·unity·游戏引擎·热更新
龚子亦1 天前
【GameFramework框架】FSM使用
学习·unity·游戏开发·游戏框架
龚子亦1 天前
【Unity开发】安卓应用开发中,用户进行权限请求
android·unity·安卓权限
君莫愁。1 天前
【Unity】相机与UI的自适应
ui·unity·c#·游戏引擎
lrh30252 天前
Custom SRP - 16 Render Scale
3d·unity·srp·render pipeline·render scale
ellis19702 天前
Unity出安卓包知识点汇总
android·unity
Robot侠2 天前
ROS1从入门到精通 2:ROS1核心概念详解(节点、话题、服务一网打尽)
unity·游戏引擎·ros·机器人操作系统
世洋Blog3 天前
装饰器模式实践:告别臃肿的继承链,优雅解耦初始化状态管理
unity·设计模式·c#·装饰器模式
老朱佩琪!3 天前
Unity原型模式
开发语言·经验分享·unity·设计模式·原型模式
老朱佩琪!3 天前
Unity组合模式
unity·游戏引擎·组合模式