Script to de-select game object in Unity RTS.

I am making a simple RTS but I need a little scripting help. I have a script with three main functions that is attached to each unit to enable Player-Unit interaction. I have in place OnMouseEnter, OnMouseExit and OnMouseDown for when the player does and doesn’t hover over the unit and for when they click on it. I now need a way so that when the unit has been clicked on and they are selected, if the player clicks off the unit (anywhere else on the screen) it is deselected… (I already have a bollean variable in place for selected).

is the code for mouse handling within the unit or is it handled by a “player” gameobject?

I would use a “player” type object

you may want to get a going and add objects when you click on them to the list, then when you click away, remove them from the list. perhaps the unit could have a

public bool selected;

or something similar to decide what to do next, im at work right now so cant write any code, but this is my thought on it.