Question by
laurenmhowie · Jul 20, 2019 at 09:21 PM ·
uiui imagepanel
Panel UI change color and revert to original color!
Hello,
I have a Panel UI element and I understand how to change the image color OnPointerEnter, but I cannot figure out how to revert its color back to the original OnPointerExit. Does anyone know how to do this???
Thankyou!
Comment
Answer by Vega4Life · Jul 21, 2019 at 03:18 AM
Will something like this help? I am just saving off the original starting color, then changing it back when the user exits.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ColorChanger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[SerializeField] Color enterColor; // Change this in the inspecctor
[SerializeField] Image image; // Or whatever you are using that has color
Color startingColor;
private void Awake()
{
// Save our starting color (Reset to this when exiting
startingColor = image.color;
}
public void OnPointerEnter(PointerEventData data)
{
image.color = enterColor;
}
public void OnPointerExit(PointerEventData data)
{
image.color = startingColor;
}
}