When I run this script I get NullReferenceException. When I call the script the Awake function call and works and returns the 3 variables with values stored in them, then when the WindowFunction function is called the variables empty again. I've tested the code and that's what I've found and unity is obeying the call order so it cannot be that either.
private Rect windowRect = new Rect(0, 0, Screen.width, Screen.height);
public Vector2 scrollPosition = Vector2.zero;
private int BSpace;
string[][] MeetRequests;
string[,] SortedStudentArray;
string[][] StudentArray;
string[][] userArray;
public int ItemSpacing = 10;
public int ItemWidth = 80;
public int ItemHeight = 30;
//when this script is first called
void Start()
{
//Fetches all user Data
string[][] userArray = GetComponent<Userdata>().CallDetail();
string[][] StudentArray = GetComponent<Userdata>().UserSorting(userArray);
//Calls the SortStudentArray method
string[,] SortedStudentArray = SortStudentList();
}
public void OnGUI()
{
//create a window
GUI.Window(0, windowRect, WindowFunction, "Meeting Request Viewer");
}
public void WindowFunction(int windowID)
{
//Creates a box with a scrolling bar to taverse the y axis
scrollPosition = GUI.BeginScrollView(new Rect(Screen.width / 6, Screen.height / 6, 350, 250), scrollPosition, new Rect(0, 0, 300, 30 * SortedStudentArray.Length));
for (int studentRow = 0; studentRow < SortedStudentArray.Length; studentRow++)
{
int NextItem = (ItemSpacing + ItemHeight) * studentRow;
GUI.Label(new Rect(ItemSpacing, NextItem, ItemWidth, ItemHeight), SortedStudentArray[studentRow, 6]);
}
GUI.EndScrollView();
}