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

public class DemonControl : MonoBehaviour
{


	public List<GameObject> Children;

	// Use this for initialization
	void Start ()
	{
		Invoke ("GetParts", 1);
		//GetParts ();
		Debug.Log (Children.Count);
		//randomAnimation ();
	}

	public void GetParts() {
		foreach (Transform child in transform) {
			Children.Add (child.gameObject);
		}
	}

	public void delayDeath() {
		Invoke ("DestroyParts", 1);
	}

	public void DestroyParts() {
		foreach (GameObject child in Children) {
			Destroy (child.gameObject);
		}
		Debug.Log ("Destroying");
		Children.Clear();
	}

	public void ChangeAnimation (string _trigger)
	{
		for (int i = 0; i < Children.Count; i++) {
			Children [i].GetComponent<Animator> ().SetTrigger (_trigger);
		}
	}

	public List<string> anims = new List<string> () { "death", "walk", "attack", "dodge", "block" };

	void randomAnimation ()
	{
		int randomAnim = Random.Range (0, 5);
		ChangeAnimation (anims [randomAnim]);
		Invoke ("randomAnimation", 2);
	}
}
