Riddle me this, Batman…
In my game, I have just built a class to handle user input and has some GUI element (or will eventually have fully realized GUI…)
I encountered this strange behavior:
class MyClass(){
//...constructor
//...properties
myText : String; //assigned in an init member function
//...member functions
function MyDraw(){
print( "class draw" );
GUI.Label( Rect( 0, 0, 300, 12 ), myText );
}
}
//an instance of myClass is created and assigned to a variable,
//then initialized all in OnStart()
function OnGUI(){
print( "OnGUI" );
myInstancedClass.MyDraw();
}
So what happens is, the console shows “OnGUI” printed as expected, but “class draw” is NOT printed-- but the GUI.Label call executes because I can see it on screen.
This threw me because I thought the class function wasn’t getting called until I put a test string into the member variable to see if it appeared on screen. So, just the print() inside the member function isn’t being called??
What’s happening here-- help me understand.