- Home /
How to make text appear only when over button(highlighted)
In the new unity u can simply changer intractable button colors with standard text. I want to make the text only appear with the button image in being hovered over my cursor or mouse. This is what I have so far ..
public class ShowText : MonoBehaviour {
public class theText = GameObject.GUIText;
void function OnMouseOver()
{
theText = ImagePosition.TextOnly;
}
void function OnMouseExit()
{
theText = ImagePosition.TextOnly;
}
}
Thank You,
Answer by fafase · Aug 10, 2015 at 04:55 AM
In the new UI you can do what you are after.
Create a button object, the text should be a child of it. Then use the interface from http://docs.unity3d.com/ScriptReference/UI.Button.html
public class ButtonControl, IPointerEnterHandler, IPointerExitHandler
{
private GameObject childText = null; // or make public and drag
void Start(){
Text text= GetComponentInChildren<Text>();
if (text != null)
{
childText = text.gameObject;
childText.SetActive(false);
}
}
public void OnPointerEnter(EventSystems.PointerEventData eventData)
{
childText.SetActive(true);
}
public void OnPointerExit(EventSystems.PointerEventData eventData)
{
childText.SetActive(false);
}
}
hi, I was attempting to figure out how to incorporate the code u gave me and I was wondering is it in JavaScript or C#, also I changed from using System.Collections to IEventSystems, but I was still having trouble does it go under monobehavior or do I get rid of that?
Answer by Chene · Aug 04, 2016 at 05:05 AM
no, you just add ,IPointerEnterHandler, IPointerExitHandler at the end of : monobehavior next to the class name.
Your answer
![](https://koobas.hobune.stream/wayback/20220611235111im_/https://answers.unity.com/themes/thub/images/avi.jpg)