Unity SetActive not working, can't switch tabs
So I've got a problem I've run into multiple times and can't seem to figure out why it's not working or what I'm doing wrong, but I am trying to set up a shop menu with tabs for different areas such as a shop tab for buying things, an upgrade tab for upgrading weapons and a stats tab for seeing current upgrades and values for the upgrades. The problem is I can't get my scripts to work with what I'm doing. Very frustrating and I can't find anything dealing with this kind of problem, or similar enough to where I can duplicate what someone else has. Here's my code: Public class SwitchTabs : MonoBehaviour { public GameObject ActivateTab; public GameObject DeactivateTab1; public GameObject DeactivateTab2; public void SwtichTab() { DeactivateTab1.SetActive(false); DeactivateTab2.SetActive(false); ActivateTab.SetActive(true); } public void OnClick() { SwitchTab(); } }
Using this, I'm trying to activate/deactivate 3 different panels with several elements under each, buttons, more panels, text, etc. I'm trying to set 2 of the parent panels to inactive and not visible, while setting the one I want, and the one clicked, to active and visible when clicked.
I have the same script in 3 different tab buttons and set the game object "ActivateTab" to the panel with the correct respective panel, and game objects "DeactivateTab(1 & 2)" to the other respective panels with their individual menus in them. However, when I start up the game and try selecting the different tab buttons to change menus, nothing changes. The tab buttons register the click, but doesn't change the menus to the correct one, or better, nothing change at all. Nothing happens apart from the button changing color and registering a click as it does by default. Am I using the method wrong, is there a better way to do this, how can I get this shop menu up and working for my game?
Again, I have 3 tab buttons on top of the UI Menu which are supposed to switch which menu I'm in like you would see in a game shop, as that's what it is, is a game shop menu. I'm trying to set the ones not clicked to inactive and set the one clicked to active so I can switch between menus.
Any ideas on how to do this correctly, or either better or more efficiently would be very appreciated if this just doesn't work for whatever the reason. Thanks guys
I'm in Unity Version 2019.3.1f1 Personal on PC if that helps
[EDIT] I am sorry I don't know if my code is posting correctly for people or if Unity Answers is shoving everything together and getting rid of my format, looks good before I post, and crap after I post. First time posting, no clue how to fix it
Your answer
Follow this Question
Related Questions
Rotation Changing Z-Coordinate Value 0 Answers
Inventory -Argument is out of range - Diagnostics to be done 1 Answer
Crashing and dont know why 0 Answers