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

public class Bubble : MonoBehaviour
{
    public GameObject boomPrefab;
    public int choice = 1;
    public GameObject playerNum;
    public Player playerScript;
    public float thisRadius;
    public Material thisMaterial;
    public Renderer thisRenderer;
    public SphereCollider thisSphereCollider;
    public float thisDelay;

    public GameObject myParent;

    // Start is called before the first frame update
    void Start()
    {
        //myParent = transform.parent.gameObject;


        playerScript = playerNum.GetComponent<Player>();
        thisRenderer = GetComponent<Renderer>();
        thisRadius = playerScript.radius;
        thisMaterial = playerScript.theMaterial;
        thisRenderer.material = thisMaterial;
        thisSphereCollider = GetComponent<SphereCollider>();
        thisSphereCollider.radius = thisRadius;
        thisDelay = playerScript.delay;

        
    }

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

        if(gameObject.transform.position.y < 0.0f)
        {
            Destroy(gameObject);
        }
    }

    private void OnTriggerEnter(Collider other)
   {
       if (other.gameObject.tag == "brick")
       {
            playerScript.bank += 2;
            playerScript.bankText.text = playerScript.bank.ToString();
           playerScript.PlaySounds();
           GameObject boom = Instantiate(boomPrefab, other.transform.position, Quaternion.identity);
           Destroy(other.gameObject);
           Destroy(gameObject,thisDelay);
           Destroy(boom, 2);
       }
   }
}
