using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerDeath : MonoBehaviour { bool invincible = true; private void Start() { StartCoroutine(vincible(0.3f)); } IEnumerator vincible(float t) { yield return new WaitForSeconds(t); invincible = false; } private void OnTriggerEnter(Collider other) { if (!invincible) { if (other.gameObject.layer == 6) { Kill(); } } } public void Kill() { GetComponentInChildren().SetBool("Die", true); GameManager.Instance.player.GetComponent().Player1.enabled = false; GameManager.Instance.player.GetComponent().Player2.enabled = false; Instantiate(GameManager.Instance.player.GetComponent().impactParticles, transform.position, Quaternion.identity); GameManager.Instance.StopGame(); GetComponent().enabled = false; Debug.Log("You lose"); GameManager.Instance.Lose(); } }