How can I count the number of prefab clones?
By NOT using findGameObjectsWithTag, (because I need to use tag for other purpose) How can I count my prefab clones in my scene?? There's this monster generator Object and I want to generate a monster every second if the number of the monster is less than a int variable 'maxMonsters' also, there's more than one monsters, so I don't want to make generator for every single monster. So I want to make only one object called generator, and make public GameObject variable to assign monsters that I want to spawn for each generators.
The code will be something like THIS: public GameObject monsterThisGeneratorWillSpawn; public Int maxMonsters;
IEnumerator MonsterSpawn()
{
yield return new WaitForSeconds(1f);
if ( //Number of Monster < maxMonsters)
{
//Monster instantiate
}
StartCorutine("MonsterSpawn")
}
Now the Important part is that I can't use tag, because there's only one tag I can use for every objects and I need to use the tag "Enemy" for every monsters. Also, I had this idea of making a script that works like a tag. For example, I just make a script named Goblin's Tag and write nothing on it. And then, instead of FindGameObjectsWithTag, use FindObjectsOfType. This seemed fine but the problem was that I need to change the Type name for every monsters. (because Goblin'sTag works only for Goblins)
Your answer
Follow this Question
Related Questions
References in prefabs! 0 Answers
Unity overwrites prefab values in runtime 0 Answers
Find with tag not working 2 Answers
instantiate a prefab not working 0 Answers
How to fix "not a prefab scene"? 1 Answer