- Home /
Array value not changing?
it;s not changing for some reason, even though i tell it to add or subtract one when i press the buttons. can you tell me what i did wrong? (the message is displaying) but not changing.
script:
@script ExecuteInEditMode static var pages : Array; var levelToLoad : String = "Level1"; var first : String; var second : String; var third : String; var fourth : String; var fifth : String; var sixth : String; var seventh : String; var rectangle : Rect; var Rectangle : Rect; var next : Rect; var back : Rect; var mssgRect : Rect; var windowRect : Rect = Rect((Screen.width / 2) - (X / 2), (Screen.height / 2) - (Y / 2), WIDTH, HEIGHT); var X : int; var Y : int; var X2 : int; var Y2 : int; var WIDTH : int; var HEIGHT : int; static var currentPage : int; private var showGUI = false;
function Awake() { currentPage = 0; showGUI = false; } function Start() { pages = Array(first, second, third, fourth, fifth, sixth, seventh); currentPage = 0; print(pages[currentPage]); } function GoUpPage() { if(currentPage < pages.length) { currentPage ++; print(pages[currentPage]); } if(currentPage > pages.length) { showGUI = true; } } function GoDownPage() { if(currentPage > 0) { currentPage --; print(pages[currentPage]); } } function OnGUI() { if(!showGUI) { windowRect = GUI.Window(0, windowRect, DoMyWindow, "Tutorial Info:"); } if(showGUI) { windowRect = GUI.Window(1, windowRect, ShowGUI, "First Level?"); } } function ShowGUI() { GUI.skin.button.wordWrap = true; if(GUI.Button(back, "<--Back")) { GoDownPage(); showGUI = false; } GUI.skin.button.wordWrap = true; if(GUI.Button(next, "Level 1-->")) { Application.LoadLevel(levelToLoad); }
GUI.DragWindow(); } function DoMyWindow() { if(!showGUI) { GUI.skin.label.wordWrap = true; GUI.Label(Rect(X2,Y2,10000000, 50), "" + System.DateTime.Now); GUI.skin.button.wordWrap = true; if(GUI.Button(rectangle, "Next")) { GoUpPage(); } GUI.skin.label.wordWrap = true; GUI.Label(mssgRect, pages[currentPage].ToString()); GUI.skin.button.wordWrap = true; if(GUI.Button(Rectangle, "Back")) { GoDownPage(); } } GUI.DragWindow(); }
thanks in advance!
(all the rects where to get the GUI positioning correct.)
Answer by Mike 3 · Dec 30, 2010 at 10:50 PM
If you're trying to get it rendering the GUI properly in editor mode, it probably won't work - unity doesn't update OnGUI much when it's not playing (Generally only does something when something happens to force a refresh)
If that's not the case and you're trying to get it to work at runtime, I'm not sure - your code works for me
for some reason, when i press the first next button, it stays on the first message, im okay with the rendering, in both times- runtime and edit mode, but the message doesn't change (i'll see if it) does the message change in your case? like mssg 1 turns to messg 2 when u click the next button, then back to mssg 1 when you clkick the back button? if so... that's great.. if not... i'll go from there.
it works fine at runtime , in edit mode it renders once then doesn't change
yeah, the rendering is great, put the UpPage and DownPage functions dont seem to be working for me.