using UnityEngine;
using System.Collections;

public class PulseText : MonoBehaviour {

    public float PulseDuration = 0.2f;
    public float ScaleAmount = 1.3f;
    private int baseFontSize = 14;

    public bool AutoPulse = false;

    // Use this for initialization
    void Start () {
        baseFontSize = gameObject.GetComponent<UnityEngine.UI.Text>().fontSize;

    }
	
	// Update is called once per frame
	void Update () {
        float scale = 1.0f;
        if (AutoPulse)
        {
            scale = 1.0f + (ScaleAmount - 1.0f) * Mathf.PingPong(Time.time, PulseDuration);
        }
        else
        {
            scale = 1.0f;
            if (Time.time < PulseEndTime)
            {
                scale = Mathf.Lerp(ScaleAmount, 1.0f, (Time.time - PulseStartTime) / PulseDuration);
            }
        }

        gameObject.GetComponent<UnityEngine.UI.Text>().fontSize = (int)(baseFontSize * scale);

    }

    public float PulseStartTime = 0.0f;
    public float PulseEndTime = 0.0f;

    public void Pulse()
    {
        PulseStartTime = Time.time;
        PulseEndTime = Time.time + PulseDuration;
    }
}
