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

public class Bubble : MonoBehaviour
{
    public MeshRenderer mesh;
    private AudioSource audioSource;
    private ParticleSystem effect;
    
    public float destroyTime = 0.5f;
    private int playerLayer;
    private int bubbleLayer;
    private bool isDetected = false;

    void Start()
    {
        playerLayer = LayerMask.NameToLayer("Player");
        bubbleLayer = LayerMask.NameToLayer("Bubble");
       
        mesh = GetComponent<MeshRenderer>();
        audioSource = GetComponent<AudioSource>();
    }

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

    }

    private void OnCollisionEnter(Collision collision)
    {
        if (isDetected) return;
        if (collision.gameObject.layer == playerLayer)
        {
            isDetected = true;
            Player player = collision.gameObject.GetComponent<Player>();
            if (player.goldenFoot)
            {
                player.goldenFoot = false;
                mesh.material = Resources.Load<Material>("Materials/GoldenTrans");
                StartCoroutine(DelayDestroy(5));
            }
            else
            {
                StartCoroutine(DelayDestroy(destroyTime));
            }
        }
    }

    IEnumerator DelayDestroy(float time)
    {
        audioSource.PlayOneShot(audioSource.clip);
        yield return new WaitForSeconds(time);
        

        
        Destroy(gameObject); // Ïú»ÙÎïÌå
    }
}
