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

public class BatCollisionHandler : MonoBehaviour {

		public GameObject deadBatPrefab;
		public UnityStandardAssets._2D.Camera2DFollow followCam;
		public AudioSource dirChange;

	  void OnCollisionEnter2D(Collision2D coll) {
		 //sprint("Bat Collision " + " with " + coll.gameObject.name);
		 if(coll.gameObject.tag == "caveFeatures")
		 	{
				 //print("death");
				 //GameStates.instance.BatDeath();
				 Invoke("BatDeath2",3);
				
				GameObject db = GameObject.Instantiate(deadBatPrefab, transform.position, Quaternion.identity);
				followCam.target = db.transform.GetChild(2); //db.GetComponent<DeadBat>().batParts[2];
				
				 gameObject.GetComponent<SpriteRenderer>().enabled = false;
				 gameObject.GetComponent<Collider2D>().enabled = false;
				 dirChange.Play();

			 }


	 }

	 void BatDeath2()
	 {
		 GameStates.instance.BatDeath();
	 }

	 public void Restart()
	 {
		 followCam.target = gameObject.transform;
		 gameObject.GetComponent<SpriteRenderer>().enabled = true;
		gameObject.GetComponent<Collider2D>().enabled = true;
	 }

	 
}
