Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

DAY 6

I changed a little the GameManager to add the ability of restart the game whe you die. And i had to add some functions to initialize things.

So, when the level is loaded the game starts

        private void Play()
        {
            _currentLevel.StartLevel();
            Instantiate(_playerPrefab, _currentLevel.PlayerStartingPoint.position, Quaternion.identity);
            _state = GameState.PLAYING_LEVEL;
        }

I guess I can let the level instantiate the player but for now I will do it in the GameManager. And when the player die, I just have to call Play again, without reloading the level.

PlayerController

        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.gameObject.CompareTag("Enemy"))
            {
                GameManager.Instance.GameOver();
                Destroy(gameObject);
            }
        }

GameManager

        public void GameOver()
        {
            _state = GameState.RESTARTING_LEVEL;
        }
        private void Update()
        {
            if (_state.Equals(GameState.PLAYING_LEVEL))
            {
                if (_currentLevel.PrisonersCount == 0 && _currentLevel.IsTeleporterActive() == false)
                {
                    _currentLevel.ActivateTeleporter();
                }
            }
            else if (_state.Equals(GameState.RESTARTING_LEVEL))
            {
                Play();
            }
        } 

I hope its work. 

  • When all the prisoners are freed, the teleporter should be activated
  • When player die the level should be restarted

Next steps: UI