Changing colour of an object during OnMouseEnter and reverting back to the original colour

I’m struggling to get the OnMouseEnter and Exit working.

The aim is to change the colour of the closest object, then return it to the original colour.

I have implemented this for the object itself but the closest object can vary in the original colour. So, I think I need a different method.

I’m trying to store the ‘current colour’, change colour, then return to original colour…

It sadly just paints everything yellow.


   void OnMouseEnter()
    {
      
      GetComponent<Renderer>().material.SetColor("_Color", mouseOverColour);

      currentColour = GetClosestEnemy(nodes).GetComponent<Renderer>().material.GetColor("_Color");
 
      GetClosestEnemy(nodes).GetComponent<Renderer>().material.color = Color.yellow;


    }
    void OnMouseExit()
    {
      
      GetComponent<Renderer>().material.SetColor("_Color", startColour);

      GetClosestEnemy(nodes).GetComponent<Renderer>().material.SetColor("_Color", currentColour);
      
    }