Text above button ?

Hello,

I was wondering are you able to when hovering over an object text could show. e.g like if a player looks at a button text would show up above it saying “Press E to open” ?

Thank you for your time, I hope you all have a great day.

Hi,

Yeah obviously you can. Here is the procedure when hover on a gameobject.

  1. Just create a texture at run time or load from resources as per your convenient.
  2. Using raycast find the object, and what kind of text you want to show.
  3. just show it on your mouse position.

For GUI Button, you can find the mouse is over a particular button. here is an example,

private var myRect = Rect(100,100, 350, 350);
function OnGUI () {
     var e : Event = Event.current;
 
     if (myRect.Contains(e.mousePosition))
       Debug.Log("Moving over the button");
 
    if (GUI.Button(myRect, "My button"))
       Debug.Log("Button Pressed");
}

when your mouse is above the GUI Button, just show the popup texture or text.
refer here for hitting button , Refer here

Hope it’ll helps.

I’d say something like this, using a bool to check if you’re hovering the button(a gameobject), and then creating a GUI.Label(). In this example I’ve centered the box for the label, you’ll have to figure out your own position algorithm for your own system.

using UnityEngine;
using System.Collections;

public class ShowText : MonoBehavior
{
	private bool showText = false;
	
	void OnMouseOver()
	{
		this.showText = true;
	}
	
	void OnMouseExit()
	{
		this.showText = false;
	}
	
	void OnGUI()
	{
		if(this.showText) {
			GUI.Label(new Rect((Screen.width / 2) - 200, Screen.height * 0.15f, 400, 20), "Press E To Open");
		}
	}
}