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

public class WaveController : MonoBehaviour {
	public bool destroy = false;
	public int waveId;
	public Vector2 center;
	public WaveColor color;
	public bool fadeToBlack;

	void OnTriggerEnter2D(Collider2D other) {
		// Check if other object is an obstacle (obstacle layer is 10)
		if (other.gameObject.layer == 10) {
			var obstacle = other.GetComponent<ObstacleController> ();
			if (obstacle.allowedWaveColor != WaveColor.All && obstacle.allowedWaveColor != this.color) {
				this.destroy = true;
			}
		}
	}

    private void OnDestroy() {
        var obj = Instantiate(GameManager.Instance.sparksPrefab, transform.position, transform.rotation);
        var ps = obj.GetComponent<ParticleSystem>();
        var m = ps.main;
        m.startColor = GetComponentInChildren<SpriteRenderer>().color;
        ps.Emit(3);
        Destroy(obj, 0.5f);
    }
}
