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

public class Coin : MonoBehaviour {

    AudioSource audio;

    // Use this for initialization
    void Start () {
        audio = GetComponent<AudioSource>();
    }
	
	// Update is called once per frame
	void Update ()
    {
        if (WaveController.enemy_wave == true)
        {
            StartCoroutine(Destroy());
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        // Player is hidden
        if (other.gameObject.tag == "Player")
        {
            Player_control.score++;
            audio.Play();
            StartCoroutine(Destroy());
        }
    }

    IEnumerator Destroy()
    {
        yield return new WaitForSeconds(0.3f);
        Object.Destroy(this.gameObject);
    }

}
