using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour
{
	private static GameManager _instance;
	public CheckHP targetHP;
	
	public GameObject targetObject;
	public Transform targetPos;

	private Rect hpRect;
	private string hpString = "Target HP: ";

	void Start()
	{
		hpRect = new Rect(10f, 10f, 100f, 50f);
	}
	
	public IEnumerator CreateTargetObject()
	{
		yield return new WaitForSeconds(5f);
		Instantiate(targetObject, targetPos.position, Quaternion.identity);
	}

	void OnGUI()
	{
		GUI.Label(hpRect, string.Concat(new string[] { hpString, targetHP.hp.ToString() }));
	}

	public void LoadNextLevel()
	{
		Application.LoadLevel(Application.levelCount == (Application.loadedLevel + 1) ? 0 : Application.loadedLevel + 1);
	}

	public static GameManager Instance
	{
		get
		{
			if (_instance == null)
			{
				_instance = FindObjectOfType(typeof(GameManager)) as GameManager;
				if (_instance == null)
				{
					GameObject gameManager = new GameObject("GameManager", typeof(GameManager));
					_instance = gameManager.GetComponent<GameManager>();
				}

			}

			return _instance;
		}
	}
}