Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

5 x 4 Button grid with custom images.

Discussion in 'UGUI & TextMesh Pro' started by katsuragi545, Sep 14, 2020.

  1. katsuragi545

    katsuragi545

    Joined:
    Jun 25, 2014
    Posts:
    38
    I'm trying to create a 5 x 4 grid of buttons that load a level based on which button they are. For example, the first button would load level 1, and the 20th button would load level 20. My game has 100 levels, so my idea is to create 5 screens 20 buttons each that the player can navigate to.

    I know how to do this using a for loop and the old Unity OnGUI button system, but I'm not sure how to do it using the Unity UI Canvas. I've seen posts about the GridLayout system, but this seems to work best when you create the UI beforehand. Because I want my buttons to have custom images, my idea is to create the grid at startup and assign the buttons during runtime. Is this a bad approach? Can anyone point me in the right direction?

    Here is a screenshot of what I'm aiming for (from Angry Birds - a 5 x 3 grid):