The small game I’m making has fire as enemies, and the player needs to put the fire out before it gets too out of hand.
I need a function to count how many GameObjects of fire are onscreen so if there’s ever more than, hypothetically, 5 fires onscreen, then it will trigger a game over. Is there something I could use to do this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
public GameObject enemies;
private float startDelay = 1;
private float spawnInterval = 4;
public float xSpawnRange;
public float bottomSpawnRange;
public float topSpawnRange;
// Start is called before the first frame update
void Start()
{
InvokeRepeating("SpawnEnemies", startDelay, spawnInterval);
}
// Update is called once per frame
void Update()
{
}
void SpawnEnemies()
{
Vector3 spawnPos = new Vector3(Random.Range(-xSpawnRange, xSpawnRange), Random.Range(bottomSpawnRange, topSpawnRange), 0);
Instantiate(enemies,spawnPos, Quaternion.identity);
}
}