- Home /
How do I randomly spawn objects in 2D game?
How do I randomly spawn few different sprites on screen so they're not overlapping or half visible on render. The sprites should immediately start shrinking until they disappear (shrinking for 3 secs).
I've tried to demonstrate what I have so far using JS, however it's overlapping and not shrinking: http://jsfiddle.net/SamuraiFox/CVX7D/
Specific to Unity, I've made these sprites prefabs and have put them into the scene from where script would spawn them into game.
I don't understand what you want but in my opinion, I think there are 2 ways to spawn an objects randomly: 1. You create a new Vector (Vector2 or Vector3 is up to your game, 2D or 3D) and set the coordinate of this vector randomly by using Random.Range function: https://docs.unity3d.com/Documentation/ScriptReference/Random.Range.html 2. If you want your sprites display randomly at defined position, you should create some empty game objects (2 or 20 or 200,...), place a tag in each of them (in order to manage them easily), then move them to any position you want and write a script for your sprites to spawn at these positions