Panel UI change color and revert to original color!


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???


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;