Change UI button text during hover.

Hi,

Is there a way to change the text that is on the UI button when it is hovered over? I understand that I could use sprites for my button, but as I just want to change a small amount of text I was hoping there might be a way of doing it without creating sprites.

Thanks,

Sure. There are multiple options. One is to change the value of Text.text. Here is a script to get you started. Attach it to the button.

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ChangeText : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {

	private Text myText;

	void Start (){
		myText = GetComponentInChildren<Text>();
	}

	public void OnPointerEnter (PointerEventData eventData)
	{
		myText.text = "Hovering";
	}

	public void OnPointerExit (PointerEventData eventData)
	{
		myText.text = "Not Hovering";
	}
}

Note you can also do this using animated transitions, or by adding event triggers, or by completely swapping the text out.