- Home /
Don't write code to spec.
How do I get cubes to spawn in rows?
I can spawn cubes by pressing the space button but I want the cubes to come down in rows and without me pressing the space button.
So you want the cubes to fall in a row and just press the space button and have the cubes fall down, right?
First, you need to define where you want these objects to fall. It depends where in space you are look at to define your row. SO, pick an axis. Then, create objects and add to them a rigidbody, which gives them physics to allow them to fall. Then just align them away from each other depending on their dimensions. Only allow the continuous creating of cubes when the player has pressed "space".
Some notes: you will want to destroy objects eventually or else it creates unwanted game objects or simply too many.
Unity Answers helps you solve your own problem, not write code for you. The solution to your problem is to write a nested 'for()' loop, and has little to do with Unity. Research nested loops, and make a try at the code. If you get stuck, post back your attempt as a new question.
No, I just want some to fall down in rows with out pressing any button.
Answer by voporak5 · Aug 05, 2013 at 03:27 AM
That's what he is saying. So what I would do is A, the For Loop. Or B, I would have a 2 Variables. 1 Variable would Count and 1 Variable would act as my constant. When Variable A reaches Variable B (The Constant), then I would reset Variable A back to 0 and then Instantiate my object. Try writing stuff out on paper to figure out the logic.
Also, don't close your Questions when they aren't resolved. I almost didn't look at this because it said [Closed]. I only checked because I was curious otherwise I could have cared less.
Follow this Question
Related Questions
What would the code look like if I want to spawn cubes of different color every spawn? 1 Answer
How to make spawn parameters 0 Answers
Delaying Spawning a Object 2 Answers
IndexOutOfRangeException: Array index is out of range. 0 Answers
how do i spawn an object x units from a hit in the racyastHit normal's direction 2 Answers