using System.Collections.Generic; using UnityEngine; class ArrowObjectPool : MonoBehaviour { public static ArrowObjectPool current; [Tooltip("Assign the arrow prefab.")] public Indicator pooledObject; [Tooltip("Initial pooled amount.")] public int pooledAmount = 1; [Tooltip("Should the pooled amount increase.")] public bool willGrow = true; List pooledObjects; void Awake() { current = this; } void Start() { pooledObjects = new List(); for (int i = 0; i < pooledAmount; i++) { Indicator arrow = Instantiate(pooledObject); arrow.transform.SetParent(transform, false); arrow.Activate(false); pooledObjects.Add(arrow); } } /// /// Gets pooled objects from the pool. /// /// public Indicator GetPooledObject() { for (int i = 0; i < pooledObjects.Count; i++) { if (!pooledObjects[i].Active) { return pooledObjects[i]; } } if (willGrow) { Indicator arrow = Instantiate(pooledObject); arrow.transform.SetParent(transform, false); arrow.Activate(false); pooledObjects.Add(arrow); return arrow; } return null; } /// /// Deactive all the objects in the pool. /// public void DeactivateAllPooledObjects() { foreach (Indicator arrow in pooledObjects) { arrow.Activate(false); } } }