GUIButton only executes once

void OnGUI() {

		if (GUI.Button(new Rect(Screen.width / 2, 0, Screen.width / 2, Screen.height), ""))	{
				transform.position += transform.forward * forwardSpeed * Time.deltaTime;
		}
	}

I want it to execute the line every frame while i hold the button.
But yet it only executes once when i press it and not multipe times.

Uhm, simply use a RepeatButton instead.

Note: Since the Unity GUI is not made for multitouch input you can’t press multiple RepeatButtons at the same time. The GUI system only has one active control at a time. You would have to roll your own solution using the Input.touches array and handle the input yourself.

@Richyrich is right. OnGui runs once a frame and buttons can only be detected on the mouse up. What you can do is test to see if the mouse is down in the area of the button, turning a certain bool to true to run what you want repeatedly, then have the release of the button set the bool false. I think it’d look like this:

//creates a rectangle to test the click position and be used for the button
Rect rect = new Rect(Screen.width / 2, 0, Screen.width / 2, Screen.height);

//the hold boolean
public bool hold;

void OnGUI(){
Event e = Event.current;

//did mouse click within the rectangle of the button?
 if ((e.type == EventType.MouseDown) && rect.Contains (Event.current.mousePosition)) { 
       hold= true; //initiate holding code
}

if (hold){
Debug.log("The button is held");
}
     
//if button is released, stop the hold code
if(GUI.Button(rect, " ")) {
          hold = false;
     }
}

Edit: I just tested the code. The object isn’t moving so you gotta tweak your move code but i used a debug to confirm that holding the button continuously does something and releasing stops. Hope it helps!