something wrong with my GUI

Hi, I have a problem with my GUI. I think this is wierd but… yeah its happened to me.
I make a simple Script like this:

GUIStyle allGUI;
void OnGUI()
{
  if(allGUI != null)
  {
     GUI.Button (new Rect(0,0,100,100), "Simple Button", allGUI);
  }
}

then i attached that script to the empty GameObject. I order from another script to set Font, Texture and anything else for this Script. However its work fine, but only when i highlighted the gameObject in Inspector Panel. Then when i`m not highlighted this gameObject in Inspector Panel, i got an error…

please, is it fine when i build the game? or this problem just happenned in Editor Only?.. Bug?

Thanks :smiley:

EDIT :
i highlighted the object in Inspector Panel :slight_smile:

EDIT :
Ok here my Script

Script1

public GameObject[] PlayerList;

void Start()
{
   PlayerList = GameObject.FindGameObjectsWithTag("Player");
}
void Update ()
{
  // .... etc
}

Script2

Script1 script;
public GUIStyle[] Button;

void Start()
{
   script = GetComponent<Script1>();
   if(script.PlayerList.Length != 0)
   {
     Button = new GUIStyle[script.PlayerList.Length];
   }
}
void OnGUI()
{
  for(int i = 0; i < script.PlayerList.Length; i++)
  {
    if(Button *!= null)*

{
if(GUI.Button(new Rect(Screen.widthi/script.PlayerList.Length,0,Screen.width/script.PlayerList.Length,30),"Thing " + i, Button))*
{
//Do Something…
}
}
}
}

you don’t seem to have initialised allGUI, neither have you told the code what to do when the button is pressed. its just a button.

GUIStyle allGUI = new GUIStyle();
void OnGUI()
{
  if(allGUI != null)
  {
    if(GUI.Button (new Rect(0,0,100,100), "Simple Button", allGUI))
    {
    Debug.Log("Pressed the Button!!");
    }
  }
}