Quantcast
Channel: Latest Questions by Abelabumba
Viewing all articles
Browse latest Browse all 6

Which is better, lots of if-statements or seperate button scripts?

$
0
0
So I'm working on a minigame that is entirely UI driven, I use buttons with gameObject.SetActive to show and hide different menus. Currently those buttons all use the same ButtonScript with public void OnClick(string text) { if (text == "toSub") { mainMenu.gameObject.SetActive(false); subMenu.gameObject.SetActive(true); } if (text == "toMain") { mainMenu.gameObject.SetActive(true); subMenu.gameObject.SetActive(false); } and so on, which works. I'm just wondering if (and why) it would be better to have seperate button scripts, one for toMain, one for toSub and so on. It's not a giant list or something, will probably cap at 10 or less. I have seperate scripts for buttons that do completely different things like adding/substracting values etc - would it make sense to put those into the above one single button script with their own ifs, too? I'm tending towards "no", but just for readability reasons. Bonus question, I feel I should do else if instead of just if on the 2nd+ cases, but I don't see any difference in behaviour, is there one?

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>