- Home /
Cannot click on image multiple times
Hi, I'm new to unity. To make the long story short, I created UI image and put a button component on it. When the code is run, all the images are disabled. When the image is clicked it opens this method that is shown in the code and a circle appears which indicates that it is clicked. But when I try to click it again it doesn't disappear when it should. This is the code:
public void buttonDice1()
{
if (!select[0].enabled)
{
select[0].enabled = true;
}
else
{
select[0].enabled = false;
}
}
This "select" is Image array. When using UI text and button component everything works perfectly. It's probably very dumb mistake that I'm not able to spot. Any suggestions?
Hi!
I don't see any issue with this particular code and especially if you said that it detects first input time, but not the second one, as well as other components work good.
$$anonymous$$y suggestion for you would be: can you place Debug.Log at the start of this function and see when Image is enabled if this function called at all?
Also, you can simplify your code this way:
select[0].enabled = !select[0].enabled;
Basically it just switches enabled state to the opposite of current.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234055im_/https://answers.unity.com/themes/thub/images/avi.jpg)