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

45 lines
1.5 KiB
C#
Raw Normal View History

using System;
using System.Collections;
using System.Collections.Generic;
using Ktyl.Util;
using UnityEngine;
using UnityEngine.InputSystem;
public class DeathZone : MonoBehaviour
{
private GameObject player;
[SerializeField] private SerialVector3 _respawnPosition;
[SerializeField] private GameEvent _playerDeath;
[SerializeField] private GameEvent _playerRespawn;
private void OnTriggerEnter(Collider other)
{
// Checks to make sure other collider is the Player. Sets player variable as Player game object and starts the coroutine.
if (other.gameObject.CompareTag("Player"))
{
player = other.gameObject;
StartCoroutine(RespawnPlayer());
}
}
// Corountine to trigger death animation, disable player movement, play fade, respawn player at last safe position and then play fade in animation and re-enable player movement.
public IEnumerator RespawnPlayer()
{
_playerDeath.Raise();
2021-03-04 17:55:29 +01:00
// yield return new WaitForSeconds(0.5f);
2021-03-04 17:55:29 +01:00
// fadeScreen.GetComponent<Animator>().SetTrigger("fadeToBlack");
yield return new WaitForSeconds(1.5f);
// move player to respawn position
player.transform.position = _respawnPosition;
2021-03-04 17:55:29 +01:00
// fadeScreen.GetComponent<Animator>().SetTrigger("fadeToClear");
yield return new WaitForSeconds(0.5f);
_playerRespawn.Raise();
yield return null;
}
}