在 Unity 中查找精灵上的像素 [英] Finding pixel on sprite in Unity

查看:20
本文介绍了在 Unity 中查找精灵上的像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Unity3d 中,我们有 RaycastHit.textureCoord 但它在 2D 中不再存在.我一直在寻找这个问题,但我没有找到任何有用的东西.

In Unity3d we have RaycastHit.textureCoord but it doesn't exist anymore in 2D. I was searching about this problem, a lot but I didn't find anything useful.

所以我想知道这个问题的解决方案,我想知道为什么像3D中的textureCoord这样的方法实际上在RaycastHit2D中不存在于2D中.

So I want to know the solution for this problem and I'm wondering why method like textureCoord in 3D doesn't exist in 2D actually in RaycastHit2D.

我也想在鼠标光标放在像素上时访问像素.

also I want to access to the pixel when mouse cursor on it.

推荐答案

它适用于 3D,因为 RaycastHit.textureCoord 需要网格碰撞器.在 2D 情况下,这很简单,因为您可以自己计算位置,因为您知道精灵命中、光标位置和精灵的大小.

It works in 3D because RaycastHit.textureCoord requires a mesh collider. In the 2D case it is way simplee because you can calculate the position yourself as you know the sprite hit, the cursor position and size of the sprite.

这篇关于在 Unity 中查找精灵上的像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆