查找像素的精灵在Unity像素、精灵、Unity

2023-09-08 09:11:37 作者:刻在年轮里的回忆

在Unity3d,我们有 RaycastHit.textureCoord ,但它并没有在二维不复存在。我正在寻找这个问题,很多,但我没有找到什么有用的东西。

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.

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

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情况下,它是这样simplee,因为你可以自己计算出的位置,你知道精灵命中,精灵的光标位置和大小。

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.