using UnityEngine;
using System.Collections;

public class ScoreFloater : FunObject {

	TextMesh _textMesh;
	float _lifetime = 0.0f;
	
	// Use this for initialization
	void Start () {
		_textMesh = transform.GetComponent<TextMesh>();
		
		Color c = _textMesh.renderer.material.color;
		c.a = 0.0f;
		_textMesh.renderer.material.color = c;
	}
	
	// Update is called once per frame
	void Update () {
		if(Globals.LastCombo > 0)
		{
			position = Globals.ComboPos;
			z = -9;
			_lifetime = 1.0f;
					
			Color cc = _textMesh.renderer.material.color;
			cc.a = 0.0f;
			_textMesh.renderer.material.color = cc;
			
			_textMesh.text = "+" + Globals.LastCombo.ToString("n0");
			
			float scale = 0.3f + ((float)Globals.LastCombo * 0.00005f);
			transform.localScale = new Vector3( scale, scale, scale );
			Globals.LastCombo = 0;
		}
		
		Color c = _textMesh.renderer.material.color;
		c.a = Mathf.Lerp(c.a, _lifetime > 0.0f ? 1.0f : 0.0f, (_lifetime > 0.0f ? 10.0f : 5.0f) * Time.deltaTime);
		_textMesh.renderer.material.color = c;
		y += 9.0f * Time.deltaTime;
		_lifetime -= 1.0f * Time.deltaTime;
	}
}
