using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; public class ApplePicker : MonoBehaviour { [Header("Set in Inspector")] public GameObject basketPrefab; public int numBaskets = 3; public float basketBottomY = -14f; public float basketSpacingY = 2f; public List basketList; public Text roundGT; // Start is called before the first frame update void Start() { basketList = new List(); for (int i = 0; i < numBaskets; i++) { GameObject tBasketGO = Instantiate(basketPrefab); Vector3 pos = Vector3.zero; pos.y = basketBottomY + (basketSpacingY * i); tBasketGO.transform.position = pos; basketList.Add(tBasketGO); } GameObject roundGO = GameObject.Find("RoundCounter"); roundGT = roundGO.GetComponent(); roundGT.text = "Round 1"; } public void AppleDestroyed() { // Destroy all of the falling apples GameObject[] tAppleArray = GameObject.FindGameObjectsWithTag("Apple"); foreach (GameObject tGO in tAppleArray) { Destroy(tGO); } // Destroy one of the baskets // Get the index of the last Basket in basketList int basketIndex = basketList.Count-1; // Get a reference to that Basket GameObject GameObject tBasketGO = basketList[basketIndex]; // Remove the Basket from the list and destroy the GameObject basketList.RemoveAt(basketIndex); Destroy(tBasketGO); roundGT.text = "Round "; roundGT.text += numBaskets - basketList.Count + 1; // If there are no Baskets left, restart the game if (basketList.Count == 0) { roundGT.text = "Game Over"; SceneManager.LoadScene("_Scene_0"); } } // Update is called once per frame void Update() { } }