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 MarkPwns1 · Sep 12, 2014 at 05:42 PM · guigridchangelevelvalue

Value won't change/GUI won't draw

So I'm trying to make a level selection screen. I've started by making a grid of buttons to fill the screen, but it doesn't seem to draw ANYTHING to the screen. I tried placing a few Debug.Log()s throughout my code. Here's my code.

 using UnityEngine;
 using System.Collections;
 
 public class LevelSelector : MonoBehaviour {
 
     public int world = 1;
     public Vector2 buttonSize = new Vector2(100, 50);
     public Vector2 Spacing = new Vector2(10, 10);
     public GUISkin skin;
     
     private int rowLengthX;
     private int rowLengthY;
 
     private int x = 10;
     private int y = 10;
 
     void Start() {
         rowLengthX = Mathf.RoundToInt(Screen.width / (Spacing.x + buttonSize.x));
         rowLengthY = Mathf.RoundToInt(Screen.height / (Spacing.y + buttonSize.y));
         Debug.Log(rowLengthX + ", " +rowLengthY);
 
         
     }
 
     void OnGUI() {
         
 
         GUI.skin = skin;
 
         int ButtonNumber = 0;
 
         for(int butx = 1; butx == rowLengthX; butx++) {
             x = Mathf.RoundToInt(butx * (Spacing.x + buttonSize.x));
             ButtonNumber++;
             for(int buty = 1; buty == rowLengthY; buty++) {
                 y = Mathf.RoundToInt(buty * (Spacing.y + buttonSize.y));
 
                 if(GUI.Button(new Rect(x, y, buttonSize.x, buttonSize.y), "Button #" + ButtonNumber)) {
 
                 }
             }
 
         }
 
         Debug.Log(x + ", " + y);
 
         x = 10;
         y = 10;
     }
 }
 

So at the end of my OnGUI(), the Debug.Log() always displays "10, 10", which leads me to believe that either A) the value is resetting itself somehow, or B) the value doesn't change at all. But if it's still at 10, 10, then the buttons should be drawing at 10, 10--but oddly enough, nothing. Does anybody know what's causing this? Does anybody also know why nothing is drawing to the screen?

All help is appreciated.

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
0
Best Answer

Answer by bilo-lwabona · Sep 14, 2014 at 10:02 PM

It's probably because of your for loop's conditional statement. Try changing the == to a

If that's not it, maybe it has something to do with the GUISkin you're using, though I doubt it. In any case, try to not assign a skin and see if nothing is being drawn. I'm pretty sure that the loops are causing the issue though.

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 MarkPwns1 · Sep 16, 2014 at 10:01 PM 0
Share

You just made me facepalm so hard! $$anonymous$$ust've misspelled "<=". Thanks alot, this has been bothering me for a while.

avatar image bilo-lwabona · Sep 16, 2014 at 10:12 PM 0
Share

haha ... no problem, something like this can happen to anyone. On the bright side, at least it was something simple to fix.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

JS changing gui box color 1 Answer

Load level that was previously loaded! 1 Answer

Positive to negative not working? 1 Answer

Change mesh to to GameObject 1 Answer

Place Inventory Into GUI Button Grid 3 Answers


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