public class Destroyedplayer : MonoBehaviour
{
public GameObject Gameover;
public Text LiveUITexts;
public AudioSource mAudioScr;
public GameObject ExplosionGo;
private IEnumerator WaitForSceneLoad() {
while (true)
{
if (Gameover.gameObject == true)
yield return new WaitForSceneLoad(3);
SceneManager.LoadScene("Title Screen");
yield return null;
}
}
int lives = 3;
public void Int()
{
const int MaxLives = 3;
lives = MaxLives;
LiveUITexts.text = lives.ToString();
}
void Start()
{
Gameover.gameObject.SetActive(false);
}
public void Update()
{
if (lives == 0)
{
Destroy(gameObject);
Gameover.gameObject.SetActive(true);
StartCoroutine(WaitForSceneLoad());
}
}
void OnTriggerEnter2D(Collider2D col)
{
mAudioScr = GetComponent<AudioSource>();
if ((col.tag == "EnemyTag") || (col.tag == "EnemyBulletTag"))
{
lives--;
mAudioScr.Play();
LiveUITexts.text = lives.ToString();
PlayExplosion();
}
}
void PlayExplosion()
{
GameObject explosion = (GameObject)Instantiate(ExplosionGo);
explosion.transform.position = transform.position;
}
}