You need a couple of things here -
- Something that will randomly spawn things
- Some way of knowing where sprites already exist so you don't spawn there
It looks like you have a handle on the former so I will cover the latter here.
For unity sprites you have a component called SpriteRenderer from which you can obtain the size of a sprite:
Vector2 size = GetComponent<SpriteRenderer>().bounds.size;
Assuming your pivot is in the top left corner, you can add this size to the transform.position to get the area the sprite takes up.
Rect objectArea = new Rect(transform.position.x, transform.position.y, size.x, size.y);
The Rect object has a handy method called contains. If you keep a list of all the Rects you've made, you could use that, or this method:
public static bool Intersect(this Rect rectA, Rect rectB)
{
return ( Mathf.Abs(rectA.x - rectB.x) < (Mathf.Abs(rectA.width + rectB.width) / 2))
&& (Mathf.Abs(rectA.y - rectB.y) < (Mathf.Abs(rectA.height + rectB.height) / 2));
}
To see if the objects intersect, if they do, try another random position.
Also depending on your use case, look into particle effects (shuriken).