-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemMaintainSpawner.cs
35 lines (31 loc) · 989 Bytes
/
ItemMaintainSpawner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections.Generic;
using UnityEngine;
namespace General.Spawners
{
public class ItemMaintainSpawner : MonoBehaviour
{
[SerializeField] private GameObject prefab;
[SerializeField] private int count;
[SerializeField] private List<GameObject> worldItems;
private void Start()
{
for (int i = worldItems.Count; i < count; i++)
{
GameObject item = Instantiate(prefab, transform.position, Quaternion.identity);
worldItems.Add(item);
}
}
private void Update()
{
for (int i = worldItems.Count - 1; i >= 0; i--)
{
if (worldItems[i] == null)
{
worldItems.RemoveAt(i);
GameObject newItem = Instantiate(prefab, transform.position, Quaternion.identity);
worldItems.Add(newItem);
}
}
}
}
}