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

public class getDestroyedByEnemiesScript : MonoBehaviour
{
    public GameObject explosionPrefab;

    // Start is called before the first frame update
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    // Called when trigger collision is detected
    private void OnTriggerEnter2D(Collider2D collision)
    {
        var hit = collision.gameObject;

        if (hit.tag == "Enemy" || hit.tag == "Bomb")
        {
            var explosion = Instantiate(explosionPrefab, transform.position, transform.rotation);
            Destroy(hit);
            Destroy(explosion, 1f);
            GameObject.Find("GameController").GetComponent<ScorecounterScript>().updateLives(-1, gameObject);
        }
    }

 

 
}
