ici_recycle_vr/Assets/Scripts/TrashSpawner.cs
Diaconescu Andrei-Alexandru 19674bfe5d Am adaugat ICI Recycle
2025-05-26 12:54:36 +03:00

35 lines
972 B
C#

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();
}
}