I am currently hiding/disabling buttons to navigate through "screens" in a unity game, with code similar to this within each onclick:
public void settingsClick()
{
SettingsBtn.SetActive(false);
SinglePlayerBtn.SetActive(false);
MultiPlayerBtn.SetActive(false);
SoundBtn.SetActive(true);
DifficultyBtn.SetActive(true);
BackBtn.SetActive(true);
}
The problem is this is horribly unscalable, for each button I add, I need to go and add in more enable/disables into each already existing button - what better options are there? I have considered making a function that sets it for each screen, and calling that (i.e. setSettingsView), but that only makes it slightly more scalable, in that I still need to go in and edit multiple functions each time I want to add a button
OnClick
can have more than one method call assigned. You can directly access the buttons you want to activate/deactivate through callinggameObject.SetActive(bool)
on each one you want to target without writing a new method. It would all be setting it up through the Editor--which also has some drawbacks for scalability. – Tartle Wizard Dec 15 '16 at 20:46