41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
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<Animator>().SetBool("Die", true);
|
|
GameManager.Instance.player.GetComponent<PlayerManager>().Player1.enabled = false;
|
|
GameManager.Instance.player.GetComponent<PlayerManager>().Player2.enabled = false;
|
|
Instantiate(GameManager.Instance.player.GetComponent<PlayerManager>().impactParticles, transform.position, Quaternion.identity);
|
|
GameManager.Instance.StopGame();
|
|
GetComponent<PlayerMovement>().enabled = false;
|
|
Debug.Log("You lose");
|
|
GameManager.Instance.Lose();
|
|
}
|
|
}
|