- Home /
Deactivate game modes until tutorial is finished?
Hello, Unity community.
So I'm building a simple game demo, and I have a main menu with three buttons; two game modes and a tutorial. I want the tutorial to be required before playing the other game modes.
How would I tell my gameManager (empty game object that handles pausing at the moment, and other things in the future) whether the tutorial has been played, and to set the other two buttons to SetActive(false) if it hasn't? I tried FindGameObjectsWithTag but that apparently puts all the gameObjects in an array, and SetActive doesn't work on arrays.
Thanks in advance :) I use C# only by the way
One day I will convince all of the Unity devs to stop using FindObjectWithTag and Object.Find("name"), as these are basically the worst ways of obtaining references. Anyway I'd assume you have a player class? Perhaps a static class that handles references to the player and such? If so, a simple bool would solve your problem.
public class Player : ScriptableObject
{
public int Level;
public bool doneTutorial;
}
then your buttons can have an onclick event like this
public void ChangeGame$$anonymous$$ode(Game$$anonymous$$ode mode)
{
if (mode != Game$$anonymous$$ode.Tutorial)
{
if (Static$$anonymous$$anager.player.doneTutorial)
{
Static$$anonymous$$anager.$$anonymous$$ode = mode;
//Other mode stuff, or handle the mode change with a getter/setter
}
}
}
Answer by jwulf · Feb 13, 2017 at 10:00 PM
You could store references to your GameMode-Buttons in the GameManager:
[SerializeField]
Button[] gameModeButtons;
In the editor's inspector, set array's size to 2 and drag the two buttons in.
Make sure the two Buttons are not set to interactable by default.
Then in your GameManager, once it is informed that the Tutorial has been completed, execute:
foreach(Button b in gameModeButtons) {
b.interactable = true;
}