1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 07:08:51 -05:00
UDRIGEEKCup2024/Assets/Scripts/SpawnCourseLimiter.cs
2024-04-21 19:52:47 -04:00

35 lines
1.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ObjectSpawner = UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets.ObjectSpawner;
namespace MAVRIC.GEEKCup
{
public class SpawnCourseLimiter : MonoBehaviour
{
[SerializeField] private List<GameObject> spawnedObjects = new List<GameObject>();
[SerializeField] private int objectLimit = 1;
[SerializeField] private ObjectSpawner objectSpawner;
private void OnEnable()
{
objectSpawner.objectSpawned += OnObjectSpawned;
}
private void OnDisable()
{
objectSpawner.objectSpawned -= OnObjectSpawned;
}
private void OnObjectSpawned(GameObject spawnedObject)
{
spawnedObjects.Add(spawnedObject);
if (spawnedObjects.Count > objectLimit)
{
Destroy(spawnedObjects[0]);
spawnedObjects.RemoveAt(0);
}
}
}
}