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

public class SpawnOnCollision : MonoBehaviour
{
    public GameObject[] prefabs;
    bool shrinking = false;
    float shrinkAmount  = 0f;

    float startTime = 0f;

    void OnCollisionEnter(Collision collision){
        if(collision.relativeVelocity.magnitude > 2 && Time.time - startTime > 2f){
            // shrinking = true;
            GameObject objToSpawn = prefabs[ Random.Range(0,prefabs.Length) ];
            Instantiate(objToSpawn, this.transform.position, Quaternion.identity);

            Destroy(this.gameObject);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        startTime = Time.time;
    }

    // Update is called once per frame
    void Update()
    {
        // if(shrinking){
        //     Vector3 currentScale = this.transform.localScale;
        //     // this.transform.localScale = currentScale * 0.99f;

        //     this.transform.localScale = Vector3.Lerp(currentScale, Vector3.zero, shrinkAmount);

        //     shrinkAmount += 0.01f * Time.deltaTime;

        //     if(shrinkAmount >= 0.9f) {
        //         Destroy(gameObject);
        //     }
        // }
    }


}
