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

public class BubbleManager : MonoBehaviour
{
    public GameObject[] BubblePrefabs;
    public Cup owner;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void SpawnBubble(int[] sequence)
    {
        int[] seq = new int[sequence.Length];
        Array.Copy(sequence, seq, seq.Length);
        //StartCoroutine(Spawn(seq));
        while (seq[seq.Length - 1] != 0)
        {
            for (int i = 0; i < seq.Length - 1; i++)
            {
                if (seq[i] > 0)//如果还有数量，则生成一个对应类型bb并减1
                {
                    seq[i]--;

                    GameObject go = Instantiate(BubblePrefabs[i],this.transform);
                    owner.bubbles.Add(go.GetComponent<Bubble>());
                }

            }
            seq[seq.Length - 1]--;
        }
    }

    public IEnumerator Spawn(int[] seq)
    {
        while (seq[seq.Length - 1] != 0)
        {
            for (int i = 0; i < seq.Length - 1; i++)
            {
                if (seq[i] > 0)//如果还有数量，则生成一个对应类型bb并减1
                {
                    seq[i]--;

                    GameObject go = Instantiate(BubblePrefabs[i], this.transform);
                    owner.bubbles.Add(go.GetComponent<Bubble>());
                }
                yield return new WaitForSeconds(0.5f);
            }
            seq[seq.Length - 1]--;
        }
        yield return null;
    }


}
