- Home /
Random ball generator?
Hello, I need help creating a game. I want to have a character on the bottom of the screen of my 2D game, and I want balls to be spawned randomly from the left and right walls. Now, everything is good so far, however I do not have any idea how to clone my already existing balls objects,randomly on the edge of the screen(right or left). Any help? Thank you!
Answer by LucasMars · Oct 08, 2014 at 07:18 PM
You would need to Instantiate a prefab/gameobject in a range of two values.
For example:
Instantiate (ball, Vector3(Random.Range(1,10), 0, 0), Quaternion.identity);
This code would clone a prefab (that you would have set in the inspector), and place it between the walls at a random position, 1 to 10. And Quaternion.identify would just set the rotation of the object.
Hope this helps.
--LucasMars
Oh right! That was me being stupid! I've edited the answer.
Your answer
Follow this Question
Related Questions
2D random object placement 0 Answers
Using arrays to randomly select an object 0 Answers
Random object placement. 1 Answer
2d obj look at limit in unity 0 Answers
i want to spawn randomly 1 Answer