Button only works once

Hey community
So I’ve gotten pretty well into Unity and how it works.
However I have en issue, that google did not help me find any answers to, hope you can.

I have this wardrobe in my game where I can change outfit on my main character.
When you activate the wardrobe an image with be enabled that has two buttons.

I wanted to show my highlighted button with a given letter (>) in front of the name, rather than changing the color tint. Seems like there aren’t any transitions available in Unity currently to do this.
So I made this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class ButtonsWardrobe : MonoBehaviour, ISelectHandler, IDeselectHandler
{
    public GameObject button;
    public Text dialogText;
    public string dialog;
    private string dialogOld;
    public bool defaultSelection;

    // Start is called before the first frame update
    void Start()
    {
        dialogOld = dialogText.text;
        if (defaultSelection)
        {
            EventSystem.current.SetSelectedGameObject(button);
        }
    }

    // Update is called once per frame
    void Update()
    {
    }
    public void OnSelect(BaseEventData eventData)
    {
        dialogText.text = dialog + dialogText.text;
    }

    public void OnDeselect(BaseEventData eventData)
    {
        dialogText.text = dialogOld;
    }
}

It works perfectly the first time I use the button.
There are two buttons: Yes and No
If you click “Yes” it will change the animation to the one with the new gear and that also changes the image for it to load on next activation (Since we want the old gear to now be in the wardrobe). This also works perfectly fine, so the second time I activate the Wardrobe it will have activated another image with two buttons Yes and No like before, which will make you put on your old clothes.

Now here comes the issue:
When I open the Wardrobe the third time I am unable to control the selector I can’t select neither yes nor no. UNLESS I click on either with the mouse.
In my tests it seems that

EventSystem.current.SetSelectedGameObject(button);

stops working when you swap between images (Since if i moved it down to void Update() it works fine and i am able to keep changing gear.
However that is not a suitable solution, since it will keep changing the selected button to the given button making you unable to choose “No”.

I hope this makes any sense at all.

-YoShI

It looks like you don’t have anything to tell the EventSystem that your clicking on your objects so the only object ever selected is the defaultSelection when you start. Try this:

public class ButtonsWardrobe : MonoBehaviour, ISelectHandler, IDeselectHandler
{
    public Text dialogText;
    public string dialog;
    private string dialogOld;

    private void Start()
    {
        dialogOld = dialogText.GetComponent<Text>().text;  //get text from text component
    }

    public void OnMouseDown()  //this tells the event system that you clicked on this object
    {
        if (Input.GetMouseButton(0))  //this will ensure this only gets triggered by a left-click
        {
            EventSystem.current.SetSelectedGameObject(gameObject);
        }
    }

    public void OnSelect(BaseEventData eventData)
    {
        dialogText.GetComponent<Text>().text = dialog + dialogText.text;
        print("I've been clicked: " + name);
    }

    public void OnDeselect(BaseEventData eventData)
    {
        dialogText.GetComponent<Text>().text = dialogOld;
        print("I've been left: " + name);
    }
}

@HellsHand
Ah right apologize.
I forgot to mention that I use the “onClick()” part of the unity inspector. Since the code it fires is in the wardrobes script. That part also works perfectly the first time you use the buttons.
We are using keyboard/joystick input to select.
That part works fine.
It appears to me as if the issue is made by me swapping images.
Each image has two buttons (Yes/No).
Edit:
This is the code I use on the OnClick()

    public void SwapGear1()
    {
        animator.SetInteger("suitNum", 1);
    }
    public void SwapGear2()
    {
        animator.SetInteger("suitNum", 0);
    }

SwapGear1 is for the yes button on the first image
SwapGear2 is for the yes button on the second image.
It makes the player change animations to ones fitting the gear the change to.

I figured out a workaround to solve this issue.
I added the code

EventSystem.current.SetSelectedGameObject(button1);

and

EventSystem.current.SetSelectedGameObject(button2);

To the script that displays the images. So it sets the focus every time the image is shown instead of only on startup. This seems to have fixed the issue.