﻿using UnityEngine;
using System.Collections;
using Holoville.HOTween;

public class LevelUpText : MonoBehaviour {

	private TextMesh txt = null;
	[SerializeField] private TextMesh txtShade = null;
	

	void Start () {
		MessageSystem.SubscribeTo (MessageKinds.LEVEL_UP, this);
		txt = GetComponent<TextMesh> ();
		txt.text = "";
		txtShade.text = "";
	}
	
	void OnLevelUp(int _level) {
		transform.position = new Vector3 (-7,transform.position.y,transform.position.z);
		txt.text = "Level " + _level;
		txtShade.text = "Level " + _level;
		StartCoroutine (this.PresentText ());
	}

	IEnumerator PresentText() {
		HOTween.To (transform,0.2f,"position",new Vector3 (0,transform.position.y,transform.position.z));
		yield return new WaitForSeconds (1.2f);
		HOTween.To (transform,0.2f,"position",new Vector3 (7,transform.position.y,transform.position.z));
	}
}
