- Home /
How to make coloured tetris-like blocks during runtime
I have 3 game objects. They are all different block types. red block, blue block, and green block.
I want to make them spawn and fall like tetris pieces in sets of three. How do I do that? When I made a tetris game I used this. The difference is I made prefabs of the tetris pieces. This was easy. There's only like 7 pieces in tetris. I made a prefab out of the one game object called block by copying it multiple times into a parent game object on the scene, then dragging the parent game object into the project asset folder.
3 blocks and 3 colours is way more pieces. And if I add even 1 more colour it'll be impossible to do it this way realistically. How can i go about spawning my 3 game objects randomly in sets of three?
//randomly selects a tetris piece
int i = Random.Range (0,groups.Length);
//spawn piece at current Position
//transform.position is position of spawner. Quaternion identity is default rotation. Quaternion is the rotation handler
Instantiate (groups [i], transform.position, Quaternion.identity);
I'm very new to this, so I don't know if I explained how I made the tetris thing properly.
Your answer
