- Home /
Why interactable in script not work?
Hello, I have a problem with a program. For some unknown reason I cannot disable a button using "button.interactable". What the program does is deactivate one button when the other is pressed. I use Unity Remote so I can check it out. And every time I press a button, the other effectively appears in the inspector with the interactable box deactivated. But it still doesn't deactivate, as I can press it. I leave the code that I use:
public class botones : MonoBehaviour, IPointerUpHandler, IPointerDownHandler
{
public Button boton1, boton2;
bool bool1, bool2;
void Update()
{
if (bool1 == true)
{
Debug.Log("Boton 1 presionado");
boton2.interactable = false;
}
else if (bool2 == true)
{
Debug.Log("Boton 2 presionado");
boton1.interactable = false;
}
if (bool1 == false)
{
boton2.interactable = true;
}
else if (bool2 == false)
{
boton1.interactable = true;
}
}
public void OnPointerUp(PointerEventData eventData)
{
if (name == "Boton1") {
bool1 = false;
}
else if (name == "Button2") {
bool2 = false;
}
}
public void OnPointerDown(PointerEventData eventData)
{
if (name == "Boton1") {
bool1 = true;
}
else if (name == "Button2")
{
bool2 = true;
}
}
}
Many thanks to those who can help me. If information is missing, do not hesitate to ask me.
Answer by mak431020 · Aug 18, 2021 at 11:44 AM
interactable = false
make the button appear on your scene but can not be clicked because the button component is disabled. If you don't want the button to appear on your scene or deactivate the button use SetActive(false)
Is not "interactable = false"? As already explained it does not work for some reason.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
turn off interactable without changing alpha 0 Answers
Distribute terrain in zones 3 Answers