using UnityEngine;
using System.Collections;

public class CheckHP : MonoBehaviour 
{
	public float hp = 150f;

	private string targetName = "Target";
	
	void OnCollisionEnter(Collision collision)
	{
		if(collision.rigidbody != null)
		{
			hp -= collision.impactForceSum.magnitude * collision.rigidbody.mass;

			if (hp <= 0)
			{
//				if (gameObject.tag.Equals(targetName))
//					GameManager.Instance.LoadNextLevel();
				
				if(gameObject.tag.Equals(targetName))
					StartCoroutine(GameManager.Instance.CreateTargetObject());

				Destroy(gameObject);
			}
		}
	}
}