// --------------------------------------------------------------------------------------------------------------------
//
//
//
// Use this on Button texts to have some color transition on the text as well without corrupting button's behaviour.
//
// developer@exitgames.com
// --------------------------------------------------------------------------------------------------------------------
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Photon.Pun.UtilityScripts
{
///
/// Use this on Button texts to have some color transition on the text as well without corrupting button's behaviour.
///
[RequireComponent(typeof(Text))]
public class TextButtonTransition : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
Text _text;
///
/// The selectable Component.
///
public Selectable Selectable;
///
/// The color of the normal of the transition state.
///
public Color NormalColor= Color.white;
///
/// The color of the hover of the transition state.
///
public Color HoverColor = Color.black;
public void Awake()
{
_text = GetComponent();
}
public void OnEnable()
{
_text.color = NormalColor;
}
public void OnDisable()
{
_text.color = NormalColor;
}
public void OnPointerEnter(PointerEventData eventData)
{
if (Selectable == null || Selectable.IsInteractable()) {
_text.color = HoverColor;
}
}
public void OnPointerExit(PointerEventData eventData)
{
if (Selectable == null || Selectable.IsInteractable()) {
_text.color = NormalColor;
}
}
}
}