Dynamic Button Tooltips

After a search, I can’t seem to find an answer to a dilemma I’m having. I’m learning c#, and have gotten to the point that I am coding a clicker/idling game to practice what I’ve learned.

I have multiple buttons, with different classes defining their content by purpose. Each set of buttons have variables attached that update the labels as needed. I’d like to have tooltips for each button that have dynamically assigned content, but I’m stuck on the Rect() part. This is what I’ve come up with:

if (GUI.Button(Rect(//STUCK), "Owned: " + employeeCount + "

LpS: " + tickValue){

   //Button stuff here.
}

I have the button stuff figured out, I just can’t seem to figure out if there’s a way to assign the corners, width, and height of the Rect() dynamically so each button shows the correct text.

Check the user manual for Rect. I tells you how to define it.

However, Unity’s OnGUI has built-in tooltip functionality, you can use it like this:

void OnGUI() {

   Vector2 mouseScreenPos = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);

    if (Event.current.type == EventType.Repaint) {
			//Show tooltip
		if (!string.IsNullOrEmpty(GUI.tooltip))
		{
			GUIContent tooltipContent = new GUIContent(GUI.tooltip);
			GUIStyle style = new GUIStyle(GUI.skin.textArea);
			style.wordWrap = true;
			float toolTipHeight = style.CalcHeight(tooltipContent, 200f);
			
			Vector2 tooltipPos;
			if(mouseScreenPos.x > Screen.width - 200) {
				tooltipPos.x = mouseScreenPos.x - 200 + 16;
			}
			else {
				tooltipPos.x = mouseScreenPos.x + 16;
			}
			
			if(Input.mousePosition.y < toolTipHeight) {
				tooltipPos.y = mouseScreenPos.y - toolTipHeight + 16;
			}
			else {
				tooltipPos.y = mouseScreenPos.y + 16;
			}
			GUI.Label(new Rect(tooltipPos.x, tooltipPos.y, 200, toolTipHeight), GUI.tooltip, "Tooltip");
		}
		}
}