using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FallCheck : MonoBehaviour {

    private TileFader tileFader;
    private Rigidbody rb;
    private Animation anim;
    private AudioSource audio;

	// Use this for initialization
	void Start () {
        tileFader = GetComponent<TileFader>();
        rb = GetComponent<Rigidbody>();
        anim = GameObject.FindGameObjectWithTag("Animation").GetComponent<Animation>();
        audio = GetComponents<AudioSource>()[1];
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Collider"))
        {
            if (tileFader!=null)
            {
                if (!tileFader.stable)
                {
                    
                    Destroy(GameObject.FindGameObjectWithTag("Floor"));
                    Destroy(GameObject.FindGameObjectWithTag("Player"),5f);
                    Destroy(gameObject, 5f);
                    rb.velocity = new Vector3(0f,-2f,0f);
                    Invoke("GameOver",4f);
                    anim.Play();
             
                    //audio.Play();
                }
            }
            
        }
    }

    void GameOver()
    {
        Application.LoadLevel("Main Menu");
    }

}
