- Home /
Button not interactable after applying script to it
The problem i'm struggling with is, i'm trying to make a game with two sets of UI which have to work at the same time, but are NOT visible at the same time. So i figured i should work with the Canvasgroup.Alpha. I wrote a small simple script which appeared to work, no errors nothin, so i tried it on a key, where it actually did work. Then i tried to apply it to a Button, after i did that, the button was not able to be interacted with, there is an EventSystem Object and the button is set to interactable. The script i wrote is pretty simple and is able to be seen down below.
public class UI_Switch : MonoBehaviour {
public CanvasGroup Default;
public CanvasGroup Shop;
void Start (){
Default.alpha = 1;
Default.interactable = true;
Shop.alpha = 0;
Shop.interactable = false;
}
void Update(){
DebugButton();
}
public void DebugButton(){
if (Input.GetKeyDown("q")){
MenuSwitch();
}
}
public void MenuSwitch(){
if (Default.alpha == 1 && Shop.alpha == 0){
Default.alpha = 0;
Default.interactable = false;
Shop.alpha = 1;
Shop. interactable = true;
} else if (Default.alpha == 0 && Shop.alpha == 1) {
Default.alpha = 1;
Default.interactable = true;
Shop.alpha = 0;
Shop. interactable = false;
}
}
}
Answer by gollumlp · Jun 20, 2019 at 07:09 PM
Just figured it out, i had the button BEHIND one of the hidden objects xD sorry for bothering, the script may be used for any reason, i mean it's simple enough so anyone can think of it (thats why i could).