using UnityEngine;
using System.Collections;

public class TextPopup : MonoBehaviour {

    public float fadeStart, fadeSpeed, riseSpeed;
    public bool outline;
    
	
	void Update ()
    {
        transform.Translate(0f, riseSpeed * Time.deltaTime, 0f);

        if (fadeStart > 0f)
            fadeStart -= Time.deltaTime;
        else
        {
            float diff = fadeSpeed * Time.deltaTime;
            if (getAlpha() <= diff)
                Destroy(gameObject);
            else
                setAlpha(getAlpha() - diff);
        }
	}

    float getAlpha()
    {
        return GetComponent<TextMesh>().color.a;
    }

    void setAlpha(float alpha)
    {
        Color color = GetComponent<TextMesh>().color;
        color.a = alpha;
        GetComponent<TextMesh>().color = color;

        if (outline)
        {
            color = GetComponent<TextOutline>().outlineColor;
            color.a = alpha;
            GetComponent<TextOutline>().outlineColor = color;
        }

    }
}
