revival/game/Assets/Scripts/Death & Respawn/PlayerDeath.cs

33 lines
840 B
C#
Raw Permalink Normal View History

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;
public void Respawn()
{
StartCoroutine(RespawnPlayerCR());
}
2021-03-12 18:41:34 +01:00
// raise death/respawn events with a given intermediate delay
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();
}
}