using UnityEngine;
using System.Collections;

public class CollectStar : MonoBehaviour {

    bool isTaken = false;
    public AudioSource collectSound;

    public void Start()
    {
        collectSound = GetComponent<AudioSource>();
    }

    public void Update()
    {
        if(isTaken)
            if (!collectSound.isPlaying)
                Destroy(gameObject.transform.parent.gameObject);
    }


     void OnTriggerEnter()
    {
        if (!isTaken)
        {
            GameData.instance.currentScore++;
            //Debug.Log("Touché");
            isTaken = true;
            collectSound.Play();
            gameObject.transform.parent.gameObject.GetComponentInChildren<MeshRenderer>().enabled = false;
        }
    }

}
