using System.Collections; using UnityEngine; public class TrashSpawner : MonoBehaviour { public GameObject[] trashPrefabs; public Transform dropTransform; public float waitForSpawn = 1f; public ParticleSystem particle; public void SpawnTrash() { GameObject trashPrefab = trashPrefabs[Random.Range(0, trashPrefabs.Length)]; StartCoroutine(SpawnTrashCoroutine(trashPrefab)); } public void SpawnSpecificTrash(GameObject specificTrash) { if (specificTrash == null) { Debug.LogWarning("TrashSpawner: specificTrash e null!"); return; } StartCoroutine(SpawnTrashCoroutine(specificTrash)); } private IEnumerator SpawnTrashCoroutine(GameObject trashPrefab) { yield return new WaitForSeconds(waitForSpawn); GameObject trash = Instantiate(trashPrefab, dropTransform.position, trashPrefab.transform.rotation); particle.Play(); } }