- Home /
Strange NullReferenceException when drawing DragableWindow
Hey all!
So I'm having this weird NullReferenceException when I draw the first button of the window that's described in the following code.
class CommDialogue { var isOpen : boolean; var target : GameObject; var window : Rect; //window rect //background area var area : Rect; var bg_img : Texture; //buttons var trade_area : Rect; var board_area : Rect; var command_area : Rect; var close_area : Rect; //labels var class_label : Rect; var message_label : Rect; var icon_label : Rect; var skin : GUISkin; function DrawWindow() { if(isOpen && target){ window = GUI.Window(0, window, DrawDialogue, "", GUIStyle.none); } } function DrawDialogue(windowID : int) { GUILayout.BeginArea(area); GUI.DrawTexture(area, bg_img); //draw background GUI.Button(trade_area, "Trade", this.skin.GetStyle("CommButton")); GUI.Button(board_area, "Board", this.skin.GetStyle("CommButton")); GUI.Button(command_area, "Command", this.skin.GetStyle("CommButton")); if(GUI.Button(close_area, "X", this.skin.GetStyle("CloseComm"))) { close(); } GUILayout.EndArea(); GUI.DragWindow(); } function close() { isOpen = false; target = null; window.x = Screen.width/2 - window.width/2; window.y = Screen.height/2 - window.height/2; } function open(target : GameObject) { close(); isOpen = true; this.target = target; } }
If I simply comment that first button, the error will simply move to the next button, until I've all of them commented, and yes, I've double checked if the skin GUISkin is inserted into the script on the Editor. Plus on that GUISkin there're two custom styles named "CommButton" and "CloseComm".
So, can any of you guys help me here? :P
Thanks in advance. João Borrego
One thing, I've now run the game again for the 3rd time, and somehow, things worked fine this time. Still I'd like to know if there's any apparent reason for the first two fails, since I can't risk it to be a "temperamental" function...
Your answer
Follow this Question
Related Questions
How to continue a dialog (GUI.Label) with answering Buttons? 1 Answer
How do i cal second question in a window? 1 Answer
Stop clicking through a GUI window 2 Answers
JavaScript GUI.Window OverPowers GUI.Button 1 Answer
Buttons in window problem 2 Answers