Switching states between scenes
I am new to game developing and trying to do basic falling block games. I want to make when the player press the space game will start and when the player dead it will show game over scene. I have 2 scenes;
one is called "StartScene" ,
one is "Main".
This is the StartScene:
and this is the Game Over scene but not actually a scene:
I could make the game over part no problem with that
In Player object i have PlayerController script and the script has this code (about gameover state)
public class PlayerController : MonoBehaviour
{
public event System.Action OnPlayerDeath;
....
}
and also I have GameOver script in Game Over Manager object (in hierarchy)
public class GameOver : MonoBehaviour
{
public GameObject gameOverScreen;
public Text timeUI;
bool isGameOver = false;
void Start()
{
FindObjectOfType<PlayerController>().OnPlayerDeath += OnGameOver;
}
void Update()
{
if (isGameOver)
{
if (Input.GetKeyDown(KeyCode.Space)) //reload the scene
{
Time.timeScale = 1; //resume game
SceneManager.LoadScene(1); //first scene
}
}
}
void OnGameOver()
{
gameOverScreen.SetActive(true);
timeUI.text = Mathf.RoundToInt(Time.timeSinceLevelLoad).ToString();
isGameOver = true;
Time.timeScale = 0; //stop game
}
}
I can't show the start scene when I clicked play. I want to show it first then when the player press the space the game will play. How can I do this?
If there is any part you don't understand pls just ask