Reputation: 9
From above picture the Login
button has functionality to allow subscribed users . I have a scenario to hide login button as well as to allow subscribed users.
For hiding I have written like this:
GameObject.FindWithTag("Login_btn").active = false;
When I write this code, it hides the login button as expected but it also disables subscribed users functionality and throws an exception
Coroutine couldn't be started because the the game object 'Login_btn' is inactive
Could you help me with this?
Upvotes: 0
Views: 76
Reputation: 58
A simpler way of doing this where you don't need to have another PNG is to just use
MyButton.GetComponent<Image>().sprite.color = Color.clear;
If your button is a sprite and not UI image that you have set the colour manually on, you can just use Color.white to revert it back otherwise just grab a reference to it before you call that first line and reference it when you want to show it again like this:
Color col = new color();
void SwitchColour(bool b){
Image myImage = Button.GetComponent<Image>();
if(!b){
col = myImage.color;
myImage.color = Color.clear;
}else myImage.color = col;
}
Upvotes: 1
Reputation: 11955
Make its texture a PNG with an alpha of 1. Therefore nobody will see it, but it'll be there to the game engine.
Upvotes: 2