mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 07:08:51 -05:00
35 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|
|
}
|