Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How would I go about making a 2x2 grid where items would automatically distribute inside the columns

Discussion in '2D' started by Jardis01, Mar 24, 2020.

  1. Jardis01

    Jardis01

    Joined:
    Mar 24, 2020
    Posts:
    5
    As the title says: How would I go about making a 2x2 grid where items would automatically distribute inside the columns? I want to have a store page, where there is a 2x2 item shop. But I need a way to automatically distribute the items in those 4 grid slots. Does anyone have any good ideas on how I could go about solving this? =)

    EDIT: The main issue I need help with is the grid itself.

    Cheers!
     

    Attached Files:

  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,323
    Given the grid as a background, you could have 4 Image components pre-positioned so that when they're assigned a sprite that sprite will appear in the correct spot on the grid. I assume you mean to use Unity's UI system (this is 2D forum).

    Code (CSharp):
    1.     void AssignItems(Image[] iconSlots, Sprite[] items)
    2.     {
    3.         for (int i = 0; i < items.Length; i++)
    4.         {
    5.             iconSlots[i].sprite = items[i];
    6.         }
    7.     }
     
  3. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
  4. Jardis01

    Jardis01

    Joined:
    Mar 24, 2020
    Posts:
    5