Tuesday, November 29, 2022
HomeGame DevelopmentHow greatest to distribute GameObjects evenly throughout a set size in Unity?

How greatest to distribute GameObjects evenly throughout a set size in Unity?


I’ve wherever from 1-5 GameObjects that I might prefer to distribute horizontally over a set distance. For instance, if there are 3 GameObjects they is likely to be unfold out with a distance X between them like so:

[G1] <–x–> [G2] <–x–> [G3]

I used to be writing my very own code to do that, after I realized that I may use a Grid Structure Group as an alternative. I began to implement that however realized one thing: every of my GameObjects has scripts which allow them to be dragged and dropped across the display.

If I exploit a Grid Structure Group to prepare the GameObjects on the display, then they’ll all be underneath a Canvas object. However with my drag-and-drop performance, I solely need the GameObjects to be organized in a 1×3 line once they first render. After that, I need to have the ability to management the situation of the GameObjects manually utilizing their Rect Remodel positions.

I’ve by no means used Canvas earlier than, and a number of the documentation mentions that they’re meant to regulate the format of UI components. My GameObjects should not actually UI components, however are letters and photos that may be dragged across the display (it is for an academic app).

Hoped for some recommendation from somebody skilled with utilizing Canvas to regulate layouts.
Ought to I:

  1. Begin off the GameObjects nested underneath the Canvas with a Grid Structure Group… however when the merchandise is picked up and dragged, unparent the GameObjects from the Canvas
  2. Discover one other strategy to initially format the GameObjects with out utilizing the Canvas
  3. One thing else solely?

Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments