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

37 lines
945 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathZone : MonoBehaviour
{
public Animator animator;
public GameObject fadeScreen;
private GameObject player;
[SerializeField] private RespawnManager respawnManager;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "Player")
{
player = other.gameObject;
StartCoroutine(respawnPlayer());
}
}
IEnumerator respawnPlayer()
{
animator.SetTrigger("IsDead");
yield return new WaitForSeconds(2);
fadeScreen.GetComponent<Animation>().Play("fadeAnim");
//yield return new WaitForSeconds(0.5f);
player.transform.position = respawnManager.getRespawnPoint();
yield return new WaitForSeconds(2);
fadeScreen.GetComponent<Animation>().Play("fadeInAnim");
yield return null;
}
}