Implement Gameover handling on player death

This commit is contained in:
Denis-Cosmin Nutiu 2019-09-07 12:31:07 +03:00
parent a9023a7efd
commit b2c59f5386
3 changed files with 25 additions and 1 deletions

View file

@ -4,6 +4,7 @@ using src.Level;
using src.Level.src.Level;
using src.Player;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace src.Managers
{
@ -86,6 +87,21 @@ namespace src.Managers
ApplicationActions.HandlePauseKey();
}
}
private IEnumerator GameOver()
{
yield return new WaitForSeconds(4f);
_levelManager.DestroyLevel();
_upgradeManager.DestroyUnclaimedUpgrades();
_gameStateManager.ResetLevel();
StartLevel();
_playerController.Respawn();
}
public void StartGameOver()
{
StartCoroutine(GameOver());
}
public void StartNextLevel()
{

View file

@ -27,6 +27,11 @@ namespace src.Managers
Level += 1;
}
public void ResetLevel()
{
Level = 1;
}
}
}

View file

@ -161,6 +161,9 @@ namespace src.Player
public void Respawn()
{
DebugHelper.LogInfo("Player is re-spawning!");
_isDead = false;
_collider2D.enabled = true;
_animator.SetBool(AnimDeath, false);
transform.SetPositionAndRotation(_respawnPosition.position, Quaternion.identity);
_animator.Play("IdleDown");
}
@ -174,7 +177,7 @@ namespace src.Player
_isDead = true;
_collider2D.enabled = false;
_animator.SetBool(AnimDeath, true);
Destroy(gameObject, 0.7f);
GameManager.Instance.StartGameOver();
}
public void OnTriggerExit2D(Collider2D other)