DAY 3
I should be able to load any level from 1 to x. When a level is loaded, I should instantiate the Player. This will be my initial aproach.
The GameManager will handle this kind of things
private void LoadNextLevel() { _currentLevel = null; _state = GameState.LOADING_LEVEL; AsyncOperation ao = SceneManager.LoadSceneAsync($"Level{_nextLevelToLoad}"); ao.completed += OnLevelLoaded; }
private void OnLevelLoaded(AsyncOperation ao) { ao.completed -= OnLevelLoaded; // Is it necessary? Level loadedLevel = FindObjectOfType<Level>(); if (loadedLevel == null) { throw new Exception("Could not find a level"); } _currentLevel = loadedLevel; Instantiate(_playerPrefab, loadedLevel.PlayerStartingPoint.position, Quaternion.identity); _state = GameState.PLAYING_LEVEL; }
The Level class holds some data like where the player should starts and how many prisoners the player has to free.
Its late here in Argentina and I have to work tomorrow. I will try to continue later :)