I am trying to write a component that spawns a sprite somewhere within another sprite’s display area. Doesn’t have to be pixel perfect, the object’s bounding box will be good enough, but not the bounding box as expanded by diagonal rotation, so renderer.bounds doesn’t really work for me.
I would also like to be able to locate points relative to a sprite. So, for example, I’d like to be able to figure out where a sprite’s top right corner is in world space. I don’t know how I could do that without the world-unit width/height data.
In this case the first value of the array is the top left corner and the second value is the bottom right corner. You can extend the method to provide the remaining two corners but you already have all the info you need.
In order to get a point within the sprite you need to do:
float x = Random.Range(array[0].x, array[1].x);
float y = Random.Range(array[0].y , array[1].y);
float z = array[0].z + 0.1f;