using UnityEngine;
using System.Collections;

public class BubbleBehavior : MonoBehaviour
{

    [SerializeField] float riseSpeed = 2f;

    [SerializeField] GameObject popEffectPrefab;
    [SerializeField] float popDuration = 0.2f;

    private bool isPopped = false;

    void Update()
    {
        if (!isPopped)
        {

            transform.Translate(Vector3.up * riseSpeed * Time.deltaTime);
            if (transform.position.y > 7f)
            {
                Destroy(gameObject);
            }
        }
    }

    void OnMouseDown()
    {
        if (!isPopped)
        {
            PopBubble();
        }
    }

    void PopBubble()
    {
        isPopped = true;

        if (popEffectPrefab != null)
        {
  
            GameObject popInstance = Instantiate(popEffectPrefab, transform.position, Quaternion.identity);
            Destroy(popInstance, popDuration);
        }

        Destroy(gameObject);
    }
}