Implement Gameover handling on player death
This commit is contained in:
parent
a9023a7efd
commit
b2c59f5386
3 changed files with 25 additions and 1 deletions
|
@ -4,6 +4,7 @@ using src.Level;
|
|||
using src.Level.src.Level;
|
||||
using src.Player;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace src.Managers
|
||||
{
|
||||
|
@ -87,6 +88,21 @@ namespace src.Managers
|
|||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
_levelManager.DestroyLevel();
|
||||
|
|
|
@ -27,6 +27,11 @@ namespace src.Managers
|
|||
Level += 1;
|
||||
}
|
||||
|
||||
public void ResetLevel()
|
||||
{
|
||||
Level = 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue