using UnityEngine;
using UnityEngine.UI;

namespace Nan.Scripts
{
    public class ScoreRenderer : MonoBehaviour
    {
        [SerializeField] private Text _text;
        private float time = 0;

        public static void Create(Vector2 pos, int score)
        {
            var scoreRenderer = Instantiate(Resources.Load<GameObject>("Prefabs/ScoreRenderer")).GetComponent<ScoreRenderer>();
            scoreRenderer._text.text = score.ToString();
            scoreRenderer.transform.position = pos;
        }

        public void Start()
        {
            time = 1;
        }

        public void Update()
        {
            time -= Time.deltaTime;
            transform.position += Vector3.up * Time.deltaTime;
            _text.color = new Color(1, 1, 1, time);

            if (time < 0)
            {
                Destroy(gameObject);
            }
        }
    }
}