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

public class WordSpawner : MonoBehaviour
{

    public GameObject wordPrefab;
    public GameObject bridge, bridgeParent;
    public Transform wordCanvas;


    public int totalBridge, currentBridge;
    
    private void Start()
    {
        bridge = wordCanvas.transform.parent.gameObject;
        bridgeParent = bridge.transform.parent.gameObject;
        totalBridge = bridgeParent.transform.childCount;
        currentBridge = 0;
    }
    private void Update()
    {

    }
    public WordDisplay SpawnWord()
    {
        //Vector3 spawnSpot = new Vector3(wordCanvas.transform.position.x - 2f,wordCanvas.transform.position.y,wordCanvas.transform.position.z);
        GameObject wordGO =  Instantiate(wordPrefab,wordCanvas);
        WordDisplay wordDisplay = wordGO.GetComponent<WordDisplay>();
        wordCanvas = bridgeParent.transform.GetChild(currentBridge).GetChild(0);
        if (currentBridge < totalBridge) currentBridge++;
        GameObject bridgetrans = wordCanvas.transform.parent.gameObject;
        bridgetrans.SetActive(true);

        return wordDisplay;
    }
    public void SetWordCanvas(int wordCanvasIndex)
    {
        wordCanvas = bridgeParent.transform.GetChild(wordCanvasIndex).GetChild(0);
    }
    
}
