problem in my code

I have a problem that the variable (Force) is increasing automaticly before i click the button ??
i want it increase only when i click the button down …

 private var rect = Rect(0, ((Screen.height / 2) - 128), 256, 256);
 
function OnGUI() {
 var e = Event.current;
    if ((e.type == EventType.MouseDown) && rect.Contains (Event.current.mousePosition))
maxForce();
Force+=6;

 if(GUI.Button(rect, "Button")) {
      Shoot();
decrease_Force();
    }
  }

Why are you trying to do this with an event in on GUI???

Use Input.MouseDown in Update.

You have missed a backet

BEFORE :

private var rect = Rect(0, ((Screen.height / 2) - 128), 256, 256);
 
function OnGUI() {
 var e = Event.current;
    if ((e.type == EventType.MouseDown) && rect.Contains (Event.current.mousePosition))
maxForce();
Force+=6;
 
 if(GUI.Button(rect, "Button")) {
      Shoot();
decrease_Force();
    }
  }

AFTER :

private var rect = Rect(0, ((Screen.height / 2) - 128), 256, 256);

function OnGUI() {
var e = Event.current;
if ((e.type == EventType.MouseDown) && rect.Contains (Event.current.mousePosition)){
maxForce();
Force+=6;
}

if(GUI.Button(rect, “Button”)) {
Shoot();
decrease_Force();
}
}