- Home /
Instantiate Objects responsively [2D]
Hi, so I was wondering about the best way to instantiate Objects in a responsive manner. I want to place a certain amount of objects evenly on a canvas in a way that takes the screen size of the user device into account. Think about a game of memory where all the cards are placed next each other and if there is no more screen space available it forms a new line of cards.
As I am still fairly new to unity I was just wondering whats the best thing to look at here. Grids, Canvas Scaling or smth I haven't even thought about? I am coming form a web development background and was hoping that there is something similar to a CSS flex layout.
Thanks =)
Answer by jackmw94 · Jan 13, 2021 at 03:12 PM
I think what you're looking for is the grid layout. Setup one of them with the constraint type as "flexible" and it will adjust how many elements in each row based on the screen size
Let me know if you get stuck using it :)
to add to this comment also in your code reference the object with the layout group on it and instantiate onto its transform aka as a parent. the layout group will do the rest as stated above :)
How are you getting on with this @colorflo? Let us know if you still need a hand! Or if this answer solved it, could you please accept it :)