using UnityEngine;
using System.Collections;

public class ScorePopup : MonoBehaviour 
{
	float m_fLife = 2.0f;
	GameObject m_Text;
	
	public void Init( int iScore )
	{
		m_Text = Util.FindChild( this.gameObject, "Text" );	
		m_Text.GetComponent<TextMesh>().text = iScore.ToString();
		
		if ( iScore<0 )
		{
			m_Text.renderer.material.color = new Color( 1,1,1,1 );
		}
		
		Vector3 vBaseScale = m_Text.transform.localScale;
		
		
		int iAbsScore = (iScore<0)?-iScore:iScore;
		float fScale = 1.0f;
		if ( iAbsScore<300  ) fScale = 0.75f;
		if ( iAbsScore>1000 ) fScale = 1.5f;
		if ( iAbsScore>4900 ) fScale = 2.2f;
		
		
		m_Text.transform.localScale = vBaseScale * fScale;
	}
	
	
	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		GameController g = GameController.GetInstance();
		
		if (g!=null)
		{
			GameObject c = g.GetCamera();
			if (c!=null)
			{
				Vector3 vTarget = transform.position - c.transform.forward;
				transform.LookAt( vTarget);
			}
		}
		
		transform.Translate(0.0f, Time.deltaTime*3.5f,0.0f );	
		
		
		if ( m_fLife<1.0f )
		{
			Color c = m_Text.renderer.material.color;
			c.a = m_fLife;
			m_Text.renderer.material.color = c;
		}
		
		m_fLife -= Time.deltaTime;
		if ( m_fLife < 0.0f ) Object.Destroy(this.gameObject);		
	}
}
