Mouse position in rect?

I’m trying to get things to display when you hover over a button or gui.
The script I have at the moment is what I mean, but I need the flexibilty of say an ‘if’ statement, so I could say, else hoverBox = false; so it would toggle off and on.

I like the idea of seeing if the mouse is in a box, maybe like a 2d box collider on the gui image? Although I’m struggling at where to start.
Thanks for any help!

	bool hoverBox = false;

	void OnMouseOver() {
		hoverBox = true;
	}
	
	void OnGUI(){
		if(hoverBox == true){
		GUI.Label (new Rect (20, 200, 70, 30), "Slash");
		}
	}

The code you have with just a bit of change will work for world objects (both 2D and 3D), and for GUIText and GUITexture objects. It can be expensive for mobile. Hit testing for GUI elements (like GUI.Buttons(), GUI.Box, or GUI.DrawTexture)) would be handled in a different way.

bool hoverBox = false;

void OnMouseEnter() {
	hoverBox = true;
}

void OnMouseExit() {
	hoverBox = false;
}

void OnGUI(){
	if(hoverBox == true){
		GUI.Label (new Rect (20, 200, 70, 30), "Slash");
	}
}