using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DisplaySign : MonoBehaviour
{
    public void Initiate(Monument monument)
    {
        var image = transform.GetComponent<Image>();
        image.sprite = Resources.Load<Sprite>(string.Format("Signs/{0}",monument.image));

        StartCoroutine(Animate(transform, 0.3f, 1f, Constants.SIGN_DURATION));
    }

	public IEnumerator Animate(Component obj, float start, float end, float lerpTime = 0.5f)
	{
		float startTime = Time.time;
		float timeSinceStart = 0f;
		float percentage = 0f;

		while (true)
		{
			timeSinceStart = Time.time - startTime;
			percentage = timeSinceStart / lerpTime;

            var value = Mathf.Lerp(start, end, percentage);
            obj.transform.localScale = new Vector2(value, value);

			if (percentage >= 1) break;

			yield return new WaitForEndOfFrame();
		}
        Destroy(gameObject);
	}
}
