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

public class Pulse : MonoBehaviour
{
	[SerializeField]
	private LayerMask objectsLayer;

	[SerializeField]
	private ParticleSystem particle;

	[SerializeField]
	private float radius = 10;

	[SerializeField]
	private AudioSource audioSource;

	[SerializeField]
	private AudioClip pulse;
	[SerializeField]
	private AudioClip pushedObjectClip;

	public void PulseDestroyer()
	{
		particle.Play();

		Collider2D[] col = Physics2D.OverlapCircleAll(transform.position, radius, objectsLayer);
		
		audioSource.PlayOneShot(pulse);

		if(col.Length > 0)
		{
			audioSource.PlayOneShot(pushedObjectClip);

			for(int i = 0; i < col.Length; i++)
			{
				if(col[i].CompareTag(Tags.gamaTag))
				{
					Vector3 dir = col[i].transform.position - transform.position;

					col[i].GetComponent<BaseObject>().SetDirection(dir);
				}
			}
		}
	}

	void OnDrawGizmosSelected()
	{
		Gizmos.color = Color.red;

		Gizmos.DrawWireSphere(transform.position, radius);
	}
}
