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

public class KillingSphere : MonoBehaviour {

	ActivableObject Act;
	List<EnemyBody> Enemies;

	// Use this for initialization
	void Start () {
		Enemies = new List<EnemyBody>();
		Act = GetComponent<ActivableObject>();
	}
	
	// Update is called once per frame
	void Update () {
		if(Act && Act.IsOn) {
			//List<EnemyBody> ToDelete = new List<EnemyBody>();
			foreach(var Enemy in Enemies) {
				if(Enemy) {
					Enemy.AddRandomPulse(transform);
					//ToDelete.Add(Enemy);
				}
			}
			/*foreach(var Enemy in ToDelete) {
				Enemies.Remove(Enemy);
				GameObject.Destroy(Enemy.gameObject);
			}*/
		}
	}

	void OnTriggerEnter(Collider other)
	{
		EnemyBody Enemy = other.GetComponent<EnemyBody>();
		if (Enemy != null)
		{
			Enemies.Add(Enemy);
		}
	}

	void OnTriggerExit(Collider other)
	{
		EnemyBody Enemy = other.GetComponent<EnemyBody>();
		if (Enemy != null)
		{
			Enemies.Remove(Enemy);
		}
	}
}
