I’m working on a main menu that has a number of buttons that the user can press at any time, switching from one panel to another. I thought it’d save time and some speed, as well as be much more elegant, to keep track of which button the user most recently pressed, and then simply turn that one off when switching to a different panel, rather than disabling all of them every time. So I wrote this:
public class MainMenu : MonoBehaviour {
public Canvas MenuCanvas;
public Canvas FirstCanvas;
public Canvas StartCanvas;
public Canvas JoinCanvas;
public Canvas PrefsCanvas;
public Canvas GuideCanvas;
public Canvas StatsCanvas;
public Canvas MusicCanvas;
public Canvas SoundCanvas;
string CanvasName;
void Awake()
{
MenuCanvas.enabled = true;
FirstCanvas.enabled = true;
CanvasName = "FirstCanvas";
}
public void JoinOn()
{
CanvasName.enabled = false;
JoinCanvas.enabled = true;
CanvasName = ("JoinCanvas");
}
The problem is, I can’t figure out how to get CanvasName to return its value, and to use that as part of the enable statement. It’s obvious why CanvasName.enabled won’t work; it’s trying to turn off the string itself and not reacting to the value of that string, but knowing that doesn’t help me much.
If anyone has any ideas about how to make this work, or better suggestions for how to implement this kind of activity tracking, I’d be grateful.