using System.Collections;
using UnityEngine;

public class BalloonController : MonoBehaviour
{

    public AudioSource aso;
    public AudioClip music;

   public GameObject igne;
   Rigidbody2D rbig;
   Animator anim;

   void Start()
   {
        rbig=igne.GetComponent<Rigidbody2D>();
        rbig.gravityScale=0;
        anim=GetComponent<Animator>();
   }



   void Update()
    {
        if (Input.GetMouseButtonDown(0)) // Sol tıklama
        {
            Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);

            if (hit.collider != null && hit.collider.gameObject == gameObject)
            {
                
                StartCoroutine(patlat());
                
            }
        }
    }

    IEnumerator patlat()
    {
        PlaySound();
        anim.SetBool("patladi",true);
        StartCoroutine(rbEkle());
        yield return new WaitForSeconds(1.05f);
        Destroy(this.gameObject);
    }

    IEnumerator rbEkle(){
        yield return new WaitForSeconds(0.55f);
        rbig.gravityScale=1;
    }

    public void PlaySound()
    {
        if (music != null)
        {
            aso.clip = music;
            aso.Play();
        }
    }
}
