Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PuneetK · Sep 04, 2013 at 06:15 PM · menulevelscrollviewscrollbarlevel select

Level selection menu (grid) and scrolling it!!

Hello friends, thanks for your answerss on previous questions. We are stuck at a very critical phase of our game right now. The question is: How to dynamically create a level selection screen something similar to angry birds. We are working on a game which has approx 40 levels per stage.

We want to make a vertical scrolling level selection screen, with about 5 levels per row. So a matrix is formed of (5x8). At any time the screen will only show 20 of these levels, so you would have to slide up or down to see the rest of the levels, just like any normal scroll view list works.

The question here is, first of all, how should we dynamically create the level selection screen. That is, the 40 level tiles should BE CREATED via script, and not manually by copy pasting 40 images in the heirarchy. This is a very big problem, as going forward with our game we would like to create atleast 200-300 levels (it is a simple board based puzzle game).

Also, once this issue is solved, another important question is how to make the scroll view work. I have UIToolkit, but am unable to make head or tail of how to do the scrollview functionality.

Please help us out. Here is the current version of the level selection screen.

alt text

As you can see, there are 20 tiles, and all 20 represent a level. I have manually placed all these tiles by duplicating the first one. And the only way I see this to work now is to manually write the level nos, etc ontop of them via guiText. This method is SERIOUSLY wrong and I know this, but I wish to know the professional or rather the more sensible way to do this.

Thanks!

screenshot (312).png (182.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by legion_44 · Sep 07, 2013 at 03:46 PM

Best way to do this is to make an for loop.

 Texture2D[] repre; //Array of textures displayed on button
 String[] lvlNames; //Array of levels(scenes) names
 int Y = 0;
 int X;
 
 for(int i = 0; i < repre.Length; i++)
 {
  if(GUI.Button(new Rect(5, Y, 50, 50), repre[i]))
  {
   Application.LoadLevel(lvlNames[i]);
  }
  y += 55;
 }

Its drawing all buttons in one column, if you want more rows, just add more fors in that for. You have to manually calculate how many rows/cols you want.

Every 'for' added in this 'for' will give you one more row.

Hope that helps

Paul

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image PuneetK · Sep 07, 2013 at 04:00 PM 0
Share

Thanks Paul. Could you explain a bit in detail, how to put the textures and level names in their respective arrays? Not only that but where do I attach this script, $$anonymous$$ain Camera?

avatar image PuneetK · Sep 07, 2013 at 09:03 PM 0
Share

I'm running your script, I'm getting a null reference exception for Texture2d[] repre;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to hide scrollbar on side of the view 0 Answers

Scroll Rect Min/Max Size 0 Answers

Custom EditorWindow Scrollbars not working with GUILayout areas 1 Answer

ScrollBar on ScrollRect not scrolling to the bottom when setting value through code 0 Answers

How do people carry over variables to other scenes? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges