Enable New Selected Image and Disable Old Selected Image?

I have multiple images on the screen. When you click one a border appears with a button to rotate and a button to move the image around the scene. After i select a different image i want to be able to disable the border around the first image and enable it on the next image. I have tried multiple approaches such as

if(Selection.activeGameObject)
        {
         
        }

And

if(!Selection.activeGameObject)
        {
         
        }

And

if (primaryImage.name != this.gameObject.name)
        {

        }

So i’ve tried to call OnPointerClick to detect if the image has been clicked. If it has then i went ahead and told it to set this GameObjects border to appear.

public void OnPointerClick (PointerEventData data)
    {
        if (gameObject.name.Equals("Clone1")
        {
            _selected = SitkcerPicker.instance.spawn2;
            _border2 = GameObject.Find("Clone2/FrameHolder/Border").GetComponentInChildren<Image>();
            _border1 = GameObject.Find("Clone1/FrameHolder/Border").GetComponentInChildren<Image>();
          
            _border1.enabled = true;
            _border2.enabled = false;
        }


}

But this seems a bit barbaric because i have about 75 different variations of images that can be instantiated. While only 5 are able to be instatiated at once. I.e, any one of them can be spawned but up to 5 max in the scene. I havent figured out how to find if another “border” is active. And i cant seem to figure out how to enable a new on while disabling the old one. Ive been on this 10 hours straight and i think im starting to over look the simplest of things.

When a finger press happens (TouchPhase.Began or GetMouseButtonDown):

  • unselect all pictures
  • raycast to see if you hit a picture

ONLY IF you hit a picture,

  • select that picture.

When I say “select” and “unselect” I mean,

“Broadly do whatever it is you want to do to consider an item visibly selected”

which in your case appears to turn on its border.

It may be helpful to have a master controlling script for each picture, and keep those in a list of active pictures, which also gives you a handy redirect to know “Picture X is selected”.

That way all the “digging around to find the border” code can go in one single place and be far easier to maintain.