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

41 lines
934 B
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathZone : MonoBehaviour
{
public SafeZone sz;
public Animator animator;
public GameObject fadeScreen;
[SerializeField] private Transform player;
private bool isDead;
private void OnTriggerEnter(Collider other)
{
isDead = true;
if (isDead == true)
{
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 = sz.safeSpawn();
yield return new WaitForSeconds(2);
fadeScreen.GetComponent<Animation>().Play("fadeInAnim");
yield return null;
isDead = false;
}
}