- Home /
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.
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.
You just made me facepalm so hard! $$anonymous$$ust've misspelled "<=". Thanks alot, this has been bothering me for a while.
haha ... no problem, something like this can happen to anyone. On the bright side, at least it was something simple to fix.
Your answer
Follow this Question
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