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

public class Clock_Fly : MonoBehaviour
{
    public Text timeTv;
    private IEnumerator MoveAnimtion;

    public void startMove(int time)
    {
        timeTv.text = "-"+ time + "<color=#FFFFFF>分钟</color>";
        //float size = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<AdaptationCamera2D>().getCameraSize;
        MoveToScore(0, 110f, 1f);
    }

    public void MoveToScore(float X, float Y, float fillTime)
    {
        Animator a = GetComponent<Animator>();
        if (a != null)
        {
            a.enabled = false;
        }

        if (MoveAnimtion != null)
        {
            StopCoroutine(MoveAnimtion);
        }
        MoveAnimtion = Move(X, Y, fillTime);
        StartCoroutine(MoveAnimtion);
    }


    private IEnumerator Move(float newx, float newy, float fillTime)
    {
        Vector3 startPos = transform.localPosition;
        Vector3 endPos = new Vector3(newx, newy, -20f);

        for (float t = 0; t <= fillTime; t += Time.deltaTime)
        {

            transform.localPosition = Vector3.Lerp(startPos, endPos, t / fillTime);

            yield return 0;
        }
        transform.localPosition = endPos;
        Destroy(transform.gameObject);
    }
}
