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

public class StartPanel : MonoBehaviour
{
    public RectTransform[] btns;
    public Vector2[] vs;
    public GameObject tipPanel;

    private void Start()
    {
        vs = new Vector2[btns.Length];
        for(int i = 0; i < btns.Length; i++)
        {
            vs[i].x = Random.Range(1, 4); 
            vs[i].y = Random.Range(1, 4);
            if (Random.Range(0, 2) == 0) vs[i].x = -vs[i].x;
            if (Random.Range(0, 2) == 0) vs[i].y = -vs[i].y;
            btns[i].GetComponent<Button>().onClick.AddListener(OnClickStart);
        }
    }

    private void Update()
    {
        for (int i = 0; i < btns.Length; i++)
        {
            btns[i].anchoredPosition += 50 * Time.deltaTime * vs[i];
            Vector2 p = btns[i].anchoredPosition;
            if (Mathf.Abs(p.x) > 859) vs[i].x = -vs[i].x;
            if (Mathf.Abs(p.y) > 422) vs[i].y = -vs[i].y;
        }
    }

    private void OnClickStart()
    {
        tipPanel.SetActive(true);
        StartCoroutine(DelayStart());
    }

    IEnumerator DelayStart()
    {
        yield return new WaitForSeconds(1f);
        Manager.Instance.begin = true;
        gameObject.SetActive(false);
    }
}
