How do I collect data while a button is pressed and use it when it is released?

I want to do something when the button is released after the while() statement. How do I test for that?

Thank you

First off, don't put code in the title of your question. Put a question in the title of your question.

You don't put a GUI button function inside of a while statement. The OnGUI function is called (roughly) once per update, so sticking it inside of a while statement will seriously mess your code up. I'm thinking that while the button is pressed, your game will most likely freeze up. You only want to use Button functions inside of if() statements, or you can grab their value and store it inside of a variable if you prefer.

What you want to do is something like this:

// C#
bool isButtonPressed;
bool lastButtonPress;

void OnGUI()
{
     if(GUI.RepeatButton(new Rect(0, 0, 100, 25), "Click me!"))
     {
          isButtonPressed = true;
     }
     else
     {
          isButtonPressed = false;
     }
}

void Update()
{
     if(isButtonPressed != lastButtonPressed)
     {
          // The state of the button changed (Pressed or released).
          // Do something here.
     }
     lastButtonPressed = isButtonPressed;
}