using UnityEngine;
using System.Collections;

public class InteractingIndicator : MonoBehaviour {

    public float maxScale = 2.0f;
    private float scaleDiff = 0f;
    private float currentScale = 0f;
    private float startScale = 0f;
    private float scaleTime;

    private float t = 0f;

    enum ScaleState { disabled, scaleUp, scaleDown };
    ScaleState scaleState = ScaleState.disabled;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	    if(scaleState == ScaleState.scaleUp || scaleState == ScaleState.scaleDown)
        {
            if (t < scaleTime)
            {
                t += Time.deltaTime;
                currentScale = QuadraticEasing(t, startScale, scaleDiff, scaleTime);
                transform.localScale = Vector3.one * currentScale;
            }
        }
	}

    public void StartUse(float scaleTime)
    {
        if (scaleState != ScaleState.scaleUp)
        {
            t = 0f;
            this.scaleTime = scaleTime;
            startScale = transform.localScale.x;
            this.scaleTime = (maxScale - startScale) / maxScale * scaleTime;
            scaleDiff = maxScale - startScale;
            scaleState = ScaleState.scaleUp;
        }
    }

    public void StopUse()
    {
        if (scaleState != ScaleState.scaleDown)
        {
            t = 0f;
            scaleTime = 0.3f;
            startScale = transform.localScale.x;
            scaleDiff = 0f - startScale;
            //scaleTime = (maxScale - startScale) / maxScale * scaleTime;
            scaleState = ScaleState.scaleDown;
        }
    }

    float QuadraticEasing(float t, float b, float c, float d)
    {
        t /= d / 2;
        if (t < 1) { return c / 2 * t * t + b; }
        t--;
        return -c / 2 * (t * (t - 2) - 1) + b;
    }
}
