GUIStyle impementation

My custom style is called “Menu”

if (from Docs)
 
static function BeginArea (screenRect : Rect, text : String) : void
 
equates to
 
GUILayout.BeginArea(Rect(40,(Screen.height-height)/2+45,width,height),"Menu");
 
Then wat does (from the docs)
 
static function BeginArea (screenRect : Rect, style : GUIStyle) : void
 
look like in code because its not
 
GUILayout.BeginArea(Rect(40,(Screen.height-height)/2+45,width,height),"Menu");

Thanks

Well there's a little problem. Unity have implemented this implicit operator to automatically convert a string into a GUIStyle. However the compiler have to statically bind the correct function and since there is an overloaded form that accepts a string at this parameter position that's the one that is used.

You have two options here:

  • Use GUI.skin.GetStyle to get the GUIStyle yourself
  • Use the another overloaded function that takes a Rect, a string and a GUIStyle

Here's the code:

// first solution
GUILayout.BeginArea(Rect(40,(Screen.height-height)/2+45,width,height),GUI.skin.GetStyle("Menu"));

// second solution
GUILayout.BeginArea(Rect(40,(Screen.height-height)/2+45,width,height),"","Menu");