Hey everybody !
I'm making a game with an enemy spawner and a GameManager who work with a Switch statement.
I would like to disable my player and my enemy spawner in "case 2:" but my spawner and my player aren't disabled ... this is my script :
void StateMachine()
{
switch (State)
{
case 0: // INTRO
endCanvas.SetActive(false);
playerShip.SetActive(true);
break;
case 1: // GAME
mobSpawner.GetComponent().enabled = true;
playerShip.SetActive(true);
break;
case 2: // END GAME
Debug.Log("End game");
mobSpawner.GetComponent().enabled = false;
Debug.Log("MobSpawner disabled");
playerShip.SetActive(false);
Debug.Log("PlayerShip disabled");
endCanvas.SetActive(true);
text_Kills.text = "You killed " + kills + " enemies !";
break;
}
The canvas appear, the console say :
"End Game"
"MobSpawner disabled"
"PlayerShip disabled"
Someone can help me ?
Thank you,
Bye, xyHeat
EDIT :
the entire script :
public class GameManager : MonoBehaviour {
public GameObject playerShip;
public GameObject mobSpawner;
public GameObject endCanvas;
public Text text_Kills;
public int State;
public int kills;
void Start()
{
State = 1;
StateMachine();
}
void StateMachine()
{
switch (State)
{
case 0: // INTRO
endCanvas.SetActive(false);
playerShip.SetActive(true);
break;
case 1: // GAME
mobSpawner.GetComponent().enabled = true;
playerShip.SetActive(true);
break;
case 2: // END GAME
Debug.Log("End game");
mobSpawner.GetComponent().enabled = false;
Debug.Log("MobSpawner disabled");
playerShip.SetActive(false);
Debug.Log("PlayerShip disabled");
endCanvas.SetActive(true);
text_Kills.text = "You killed " + kills + " enemies !";
break;
}
}
public void ToIntro()
{
State = 0;
StateMachine();
}
public void ToGame()
{
State = 1;
StateMachine();
}
public void ToEndGame()
{
State = 2;
StateMachine();
}
}
↧