Hello,
I need a spawner who can spawn an object in random position on an image. I know there are already too much solution for “spawning” but in this case some of images doesnt fit standart rectangle shape, and i dont want to spawn something on transparent areas of base image. How can i manage that thing? How can i force the spawner for using base image’s non-transparent areas borders?
If you add a mesh collider to an object, you can then cast a ray at it and retrieve the UV coordinates of the hit point using Unity - Scripting API: RaycastHit.textureCoord . Then, you could use GetPixel() to get the pixel value of the texture at that point and test its alpha component to see if it’s transparent - if so, pick another point somewhere within the bounds of the mesh until you get an opaque one.
That’s a generic solution and not optimised for either 2d or UI in particular, but it might give you a starting point to work from.