- Home /
How can I spawn gameObjects within a circle radius?
In Unity2D
Answer by Philosophbot · Nov 15, 2019 at 07:33 PM
Sorry if this answer is not what you are looking for, but your question is pretty vague. If you were looking for an idea of what do to, you could take the Transform.position of the game object that the circle is supposed to be or be attached to and then spawn the object from the position of the Transform.position plus x,y, and z values that are less than or equal to the radius of the circle.
So for example: Let's say you have a Game Object called circle and that you have a Game Object called spawnMe. you store the Game Objects transform with the name circleTransform. An example of how to Instantiate the spawnMe object within the circle would be:
Instantiate(spawnMe, circleTransform.position + new Vector3(*some value less than or equal to the radius*, *some value less than or equal to the radius*, some value less than or equal to the radius*, Quaternion.identity);
This would spawn in a cube. What you need is:
Instantiate(spawn$$anonymous$$e, circleTransform.position + Vector3.insideUnitSphere * radius, Quaternion.identity);