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

public class EarthquakeDestruction : MonoBehaviour
{
    [SerializeField]
    float p_myRadius;
    [SerializeField]
    float p_mySpeed;

    void Start ()
    {
        StartCoroutine(Explosion());
    }

    IEnumerator Explosion()
    {
        while (transform.localScale.x < p_myRadius)
        {
            Vector3 newScale = transform.localScale;
            newScale *= 1 + (p_mySpeed * Time.deltaTime);
            transform.localScale = newScale;
            yield return new WaitForEndOfFrame();
        }
        Destroy(this.gameObject);
    }

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Human")
        {
            collision.gameObject.GetComponent<HumanScript>().Death();
        }
        else if (collision.gameObject.tag == "Building")
        {
            collision.gameObject.GetComponent<BuildingScript>().Death();
        }
    }
}
