using UnityEngine;
using System.Collections;

public class HitByObject : StageBeatEvent {

	public string targetTag;
	public int needHitCount;

	public Actor bowManActor;
	public bool noDuck;

	void OnTriggerEnter2D(Collider2D other) {

		Debug.Log("obj in trigger " + other.name);

		if( other.CompareTag(targetTag) ) {
			needHitCount -= 1;
			if( needHitCount <= 0 ) {
				BeatStage();
			}
		}
	}

	public void CheckBowmanDuck() {
		if(bowManActor.kind == Actor.Kind.Player) {
			Debug.Log("[Debug] Bowman duck check");
			if(!noDuck) {
				Debug.Log("Clear");
				GameController[] gcs = FindObjectsOfType<GameController>();
				if( gcs.Length > 1 ) {
					Debug.LogError("[Fatal] GameController exists more than 1!!");
				} else if(gcs.Length == 1) {
					gcs[0].success = true;
				}
			}
		}
	}

}
