Why does it give me an error in this small java script for sprint?

var curStam : float = 100.0;
var maxStam : float = 100.0;

    var isSprinting : boolean = false;
     
    var stamCooldown : boolean = false;
     
     
    function OnGUI () {
      GUI.Label(ResizeGUI(Rect(430,350,50,50)), "" + curStam);
      
    
      
      if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run" && curStam > 0 && stamCooldown == false)) {
      isSprinting = true;
     }
            else {
                    isSprinting = false;
                   
           
            }
     
     
            if(isSprinting == true && curStam >= 0) {
           
            curStam--;
           
    }
     
            if(isSprinting == false && curStam < 100.0) {
     
            curStam++;
     
    }
     
     
            if(curStam == 0) {
           
            stamCooldown = true;
           
            }
           
            if(curStam == 1.0) {
           
            stamCooldown = false;
           
           
            }
    }


function ResizeGUI(_rect : Rect) : Rect
{
    var FilScreenWidth = _rect.width / 800;
    var rectWidth = FilScreenWidth * Screen.width;
    var FilScreenHeight = _rect.height / 600;
    var rectHeight = FilScreenHeight * Screen.height;
    var rectX = (_rect.x / 800) * Screen.width;
    var rectY = (_rect.y / 600) * Screen.height;
 
    return Rect(rectX,rectY,rectWidth,rectHeight);
}

I’m trying to make a runescape style sprint bar, if you click on a button, it will activate sprinting so if you click somewhere, it sprints there, and when the curStam hits 0, you cant sprint anymore. Problem is the button, it worked with holding Shift in an update function, but I want it in a OnGUI.

Error is:

MissingMethodException: UnityEngine.GUI.Button

I tried to fix it by RepeatButton, does work tho. Any help greatly appreciated.

change

if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run" && curStam > 0 && stamCooldown == false))

to

if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run") && curStam > 0 && stamCooldown == false)

EDIT

if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run")) 

returns true if you click on the button so every time you clicked on the button, isSprinting was set to true, but the next frame it was set back to false because you didn’t keep clicking. With the following code, if you click on the button, isSprinting will be set to true if it was false and vice versa.

if (GUI.Button(ResizeGUI(Rect(350,350,50,50)), "Run")){
	Debug.Log("clicked");
		isSprinting = !isSprinting;
	}
	
	
	
	if(isSprinting == true && curStam > 0) {
		Debug.Log("curstamdown" + curStam);
		curStam--;
		
	}
	else if(curStam == 0)
	{
		isSprinting = false;
	}
	
	if(isSprinting == false && curStam < 100.0) {
		Debug.Log("curstam up" + curStam);
		curStam++;
		
	}