using UnityEngine;
using System.Collections;

public class Shaman : MonoBehaviour
{
		public float strength;
		public float shootDistance = 10;
		public float shootInterval = 1;
	
		public Spear spearPrefab;
		
		float shootTimer = 0;
		
		Animator animator;
		
		void Start ()
		{
				animator = this.GetComponent<Animator> ();
		}
		
		void Update ()
		{		
				shootTimer += Time.deltaTime;
				if (shootTimer > shootInterval) {
						if (Vector2.Distance (MainCharacter.inst.transform.position, this.transform.position) < shootDistance) {
								animator.SetTrigger ("Attack");
								Invoke ("Shoot", 0.5f);
								shootTimer = 0;
						} else {
								//animator.SetTrigger ("Idle");
						}
				}
		}
		
		void Shoot ()
		{		
				Spear spear = Instantiate (spearPrefab) as Spear;
				spear.transform.parent = this.transform.parent;
				spear.transform.position = this.transform.position;
				
				spear.Init (MainCharacter.inst.transform.position);
		}
}
