using UnityEngine; using System.Collections; using System.Collections.Generic; 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 AudioClip fallSound; private bool hasPlayedSound = false; public List basketList; void Start() { basketList = new List(); for (int i = 0; i < numBaskets; i++) { GameObject tBasketGO = Instantiate(basketPrefab) as GameObject; Vector3 pos = Vector3.zero; pos.y = basketBottomY + (basketSpacingY * i); tBasketGO.transform.position = pos; basketList.Add(tBasketGO); } } public void AppleDestroyed() { GameObject[] tAppleArray = GameObject.FindGameObjectsWithTag("Apple"); foreach (GameObject tGO in tAppleArray) { Destroy(tGO); } int basketIndex = basketList.Count - 1; GameObject tBasketGO = basketList[basketIndex]; basketList.RemoveAt(basketIndex); Destroy(tBasketGO); if (basketList.Count == 0) { PlayerPrefs.SetInt("FinalScore", Basket.currentscore); PlayerPrefs.Save(); SceneManager.LoadScene("_GameOverScene"); } } void Update() { if (transform.position.y < -15f && !hasPlayedSound) { hasPlayedSound = true; AudioSource.PlayClipAtPoint(fallSound, Camera.main.transform.position); Destroy(gameObject); } } }