- Home /
2D random object placement
Hi people. Im trying to make a 2d game were you dodge rocks falling from the sky. and heres whats wrong. im trying to make a csharp script thats controls the rocks and spawns them at random position on the 2d stage. The script wouldt have a timer that spawned a rock maybe every second so there would always be a flow of rocks. Im not asking for a finished script. just some help to write one. Anders
Assu$$anonymous$$g you've setup your game in a standard way...action occurring on the XZ plane with the 'Z' = 0 you can calculate the position by:
pos = Vector3(Random.Range($$anonymous$$X, maxX), startHeight, 0.0);
I would start by looking up Random and Instantiate. Unity has its own Random, but so does .NET so you could use either one. You can set a timer up inside a method to instantiate a rock every couple of seconds at a random position with these. If you don't know how to make a timer, look up Time in unity as well. I Hope this helps get you started!
Your answer
Follow this Question
Related Questions
Random object placement. 1 Answer
Random Object Spawnning? 1 Answer
Random ball generator? 1 Answer
Unity 2D Random Movement 1 Answer
Importing 2D objects into Unity 5 Answers