using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ItemSpawner : MonoBehaviour
{
[SerializeField] private GameObject[] ItemsPrefabs;
[SerializeField] private Cell lastCellColumn;
private int startSpawnCount;
void Start()
{
StartCoroutine(StartSpawn());
}
IEnumerator ItemSpawn()
{
if (lastCellColumn.ItemInCell == null)
{
Instantiate(ItemsPrefabs[Random.Range(0, ItemsPrefabs.Length)], transform.position, Quaternion.identity);
yield return new WaitForSecondsRealtime(0.5f);
StartCoroutine(StartSpawn());
}
else
{
if (gameObject.name == "SpawnPoint4")
{
yield return new WaitForSecondsRealtime(0.5f);
MatchesChecker.Instance.ThreeInRow();
MatchesChecker2.Instance.ThreeInRow();
}
yield return new WaitForSecondsRealtime(0.5f);
StartCoroutine(ItemSpawn());
}
}
IEnumerator StartSpawn()
{
if (startSpawnCount <= 4)
{
startSpawnCount++;
Instantiate(ItemsPrefabs[Random.Range(0, ItemsPrefabs.Length)], transform.position, Quaternion.identity);
yield return new WaitForSecondsRealtime(0.5f);
StartCoroutine(StartSpawn());
}
else
{
StartCoroutine(ItemSpawn());
yield return null;
}
}
}