Is there a way to combine the Update and OnGUI functions?

I need to combine them so that my GUI constantly updates.

private var IsRKeyPressed : boolean = false;
private var IsRocksButtonPressed : boolean = false;

function Start () {

}

function Update () {


//Is R key being held down
				if (Input.GetKey (KeyCode.R)) {
						IsRKeyPressed = true;
		
				} else {
						IsRKeyPressed = false;
				}
				//Opens Rock Menu

}
function OnGUI () {

if (IsRKeyPressed == true){
 
 //Rock Category (With rock items/models)
 if (GUI.Button (Rect (0,20,100,100), "Rocks")) {
 IsRocksButtonPressed = true;
   if(IsRocksButtonPressed == true) {
       if (GUI.Button (Rect (200,50,100,100), "Small Rock")) {
      }
}}}}

Your code requires that you press the R key to make a GUI.Button show up, which you will need to continually hold down to get another button to show up… so you will never be able to click the second button because if you let go of the first the second will disappear.

I’m a c# guy, but maybe try something like…

      function OnGUI () {
            if (IsRKeyPressed == true){
                if (GUI.Button (Rect (0,20,100,100), "Rocks")) {
                    IsRocksButtonPressed = true;
                }
            }
            if(IsRocksButtonPressed == true) {
                if (GUI.Button (Rect (200,50,100,100), "Small Rock")) {
                    //Do Something here
                    isRocksButtonPressed = false;
                }
            }
        }

This way you don’t need to hold the R button and the first GUI button after you have enabled isRocksButtonPressed