using UnityEngine;
using System.Collections;

public class ProjectileCollision : MonoBehaviour {

	public int DamageDealt=1;
	public float StunTime=0.1f;
	public float Knockback=0.5f;

	public Transform ExplosionPrefab;
	// TODO add code hook to projectile collision
	
	private GameController gc;	
	private GameObject cameraGO;

	// Use this for initialization
	void Start () {
		GameObject go = GameObject.Find ("GameController");
		gc = go.GetComponent<GameController>();
		cameraGO = GameObject.Find ("Main Camera");
	}
	
	void OnCollisionEnter2D(Collision2D coll) {
        ActorStatus stat = coll.gameObject.GetComponent<ActorStatus>();
        if (stat != null)
            stat.TakeDamage(DamageDealt);

		if(ExplosionPrefab != null)
		{
			Transform exp = (Transform) GameObject.Instantiate(ExplosionPrefab);
			exp.position = transform.position;
		}

		if(cameraGO != null)
			iTween.ShakePosition(cameraGO, new Vector3(0.1f, 0.1f, 0), 0.05f);

		GameObject.Destroy (gameObject);
	}
}
