GuiStyle[] array keys

So, I haven’t spent a whole lot of time trying to figure this out, but it seems like what I’m doing SHOULD be working.

So, I have this code…

public class Startup : MonoBehaviour {
	public GUIStyle[] styles;
	
	public void OnGUI()
	{
		GUI.Label (new Rect (80, 22, 100, 30), "**", styles["Label"]);
		//Cannot implicitly convert type `string' to `int'
		
		GUI.Label (new Rect (80, 22, 100, 30), "**", styles.Label);
		//does not contain a definition for `Label' (which makes sense)
		
		GUI.Label (new Rect (80, 22, 100, 30), "**", styles[0]);
		// EDIT: throws Array index is out of range.
	}
}

I’ve defined a “Label” style to access already, as seen below.

26790-screenshot_2.png

I’d really like to be able to access my Styles with styles[“style_name”]; Am I able to accomplish this?

The first way is to not use a GUIStyle array, and to set a GUISkin, and define your styles in that. It shall help. Then it is simple to use(written in CSharp):

 public GUISkin mySkin = null;

 void OnGUI(){
  GUI.skin = mySkin;
  
  GUI.Label (new Rect (80, 22, 100, 30), "**", "Label");
 }

The second - more difficult. Set enum in compliance with your array of styles. For example:

 public GUIStyle[] styles;

 public enum enStyles {
  Label = 0,
 };

 public void OnGUI() {
  GUI.Label (new Rect (80, 22, 100, 30), "**", styles[(int)enStyles.Label]);
 }

The third method, it to create own class with override functions.