Made windowspawner keep track of spawned window count
This commit is contained in:
@@ -20,9 +20,11 @@ namespace InterfaceOff
|
||||
|
||||
[field: SerializeField] private SpawnableWindowType[] WindowTypes { get; set; }
|
||||
private int TotalSpawnWeight { get; set; }
|
||||
|
||||
[field: SerializeField] public int SpawnedWindowCount { get; private set; }
|
||||
|
||||
[field: SerializeField] public bool AutoSpawn { get; private set; } = true;
|
||||
private int SpawnCounter { get; set; }
|
||||
private int TimeTillNextSpawn { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -74,14 +76,19 @@ namespace InterfaceOff
|
||||
Debug.LogError("How did this happen");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Updates the window trackers */
|
||||
SpawnedWindowCount++;
|
||||
|
||||
/* Makes sure the WindowInteractions and WindowComponents are set up before passing to user code */
|
||||
windowBase.Interactions = go.GetComponent<WindowInteractions>();
|
||||
windowBase.Interactions.SetAttachedTo(windowBase);
|
||||
|
||||
windowBase.Components = go.GetComponent<WindowComponents>();
|
||||
windowBase.InstantiateWindowBase();
|
||||
windowBase.InstantiateWindowBase(creator: this);
|
||||
}
|
||||
|
||||
public void AlertOfDespawnedWindow() => SpawnedWindowCount--;
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
@@ -92,10 +99,10 @@ namespace InterfaceOff
|
||||
const int MAXIMUM_SPAWN_TIME = 5 * TICKS_PER_SECOND;
|
||||
|
||||
/* Decreases the spawn counter and spawns if at 0 */
|
||||
SpawnCounter = Math.Max(0, SpawnCounter - 1);
|
||||
if (SpawnCounter == 0)
|
||||
TimeTillNextSpawn = Math.Max(0, TimeTillNextSpawn - 1);
|
||||
if (TimeTillNextSpawn == 0)
|
||||
{
|
||||
SpawnCounter = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME);
|
||||
TimeTillNextSpawn = Random.Range(MINIMUM_SPAWN_TIME, MAXIMUM_SPAWN_TIME);
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user