using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine;

//best code in the universe

public class PlayerHit : MonoBehaviour {

    public Text text;
    public Animator game;
    public AudioSource music;
    public AudioSource dSound;
    public GameObject player;
    public GameObject explosion;
    public GameObject[] bullets;
    public GameObject[] parts;
    bool dead;

    void OnParticleCollision(GameObject other)
    {
        game.enabled = false;
        music.Stop();
        dSound.Play();
        text.enabled = true;
        dead = true;
        player.GetComponent<PlayerTurn>().enabled = false;
        GetComponent<BoxCollider>().enabled = false;
        Instantiate(explosion, player.transform.position, Quaternion.identity);
        bullets[0].SetActive(false);
        bullets[1].SetActive(false);
        bullets[2].SetActive(false);
        bullets[3].SetActive(false);
        parts[0].SetActive(false);
        parts[1].SetActive(false);
        GetComponent<MeshRenderer>().enabled = false;
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space) && dead)
        {
            int scene = SceneManager.GetActiveScene().buildIndex;
            SceneManager.LoadScene(scene, LoadSceneMode.Single);
        }
    }
}
