2021-03-12 12:52:56 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using Ktyl.Util;
|
|
|
|
|
|
|
|
public class PlayerDeath : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private SerialVector3 _respawnPosition;
|
|
|
|
[SerializeField] private GameEvent _playerDeath;
|
|
|
|
[SerializeField] private GameEvent _playerRespawn;
|
|
|
|
|
2021-03-12 16:58:18 +01:00
|
|
|
public void Respawn()
|
|
|
|
{
|
|
|
|
StartCoroutine(RespawnPlayerCR());
|
|
|
|
}
|
|
|
|
|
2021-03-12 18:41:34 +01:00
|
|
|
// raise death/respawn events with a given intermediate delay
|
2021-03-12 16:58:18 +01:00
|
|
|
public IEnumerator RespawnPlayerCR()
|
2021-03-12 12:52:56 +01:00
|
|
|
{
|
|
|
|
_playerDeath.Raise();
|
|
|
|
|
|
|
|
yield return new WaitForSeconds(1.5f);
|
|
|
|
|
|
|
|
// move player to respawn position
|
2021-03-12 18:41:34 +01:00
|
|
|
transform.position = _respawnPosition;
|
2021-03-12 12:52:56 +01:00
|
|
|
|
2021-03-12 18:41:34 +01:00
|
|
|
// need to wait a bit for the respawn to actually work?? >:v
|
2021-03-12 12:52:56 +01:00
|
|
|
yield return new WaitForSeconds(0.5f);
|
2021-03-12 18:41:34 +01:00
|
|
|
|
2021-03-12 12:52:56 +01:00
|
|
|
_playerRespawn.Raise();
|
|
|
|
}
|
|
|
|
}
|