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

public class ShardOnImpact : MonoBehaviour {

    public GameObject shard;
    float starttim;
    bool started;

    void OnCollisionEnter(Collision collision) {
        if (!started) return;
        if (Time.time - starttim < 1f) return;

        starttim = Time.time;
        if (GetComponent<VaseBreakScript>()) {
            
            Destroy(GetComponent<SphereCollider>());
            GetComponent<Rigidbody>().velocity = new Vector3(
                GetComponent<Rigidbody>().velocity.x,
                -2,
                GetComponent<Rigidbody>().velocity.z);
            Destroy(this,0.5f);
            return;
        }

        for (int i = 0; i < 10; i ++) {
            GameObject go = 
                GameObject.Instantiate(shard,
                transform.position + new Vector3(Random.Range(-1f, 1f),
                Random.Range(-1f, 1f),
                Random.Range(-1f, 1f)), Quaternion.identity);
            go.GetComponent<Rigidbody>().velocity = new Vector3(Random.Range(-6f, 6f),
                2,
                Random.Range(-2f, 2f));
        }
        
        Destroy(gameObject,0.01f);
    }

    public void StartMe() {
        started = true;
        starttim = Time.time;
    }

}