- Home /
How do you spawn an object in a random place in a set area?,How do you spawn a set object in a random location in a set area
im making an endless dodging game and i need the obstacles to spawn randomly on the right of the screen
Can anyone help? i program in c# thanks :)
screenshot-2.png
(23.9 kB)
Comment
Answer by tehpro_unity · Dec 31, 2018 at 12:21 AM
You can use
Vector 2 randomPosition = new Vector2(Random.Range(0, 10), Random.Range(10, 20));
where the parameters are x and y (horizontal and vertical) If you want to make random position from a given point you can just add this position as
transform.position + new Vector2...
Your answer
![](https://koobas.hobune.stream/wayback/20220612184813im_/https://answers.unity.com/themes/thub/images/avi.jpg)