Hi all. I’ve got a strange problem. There are 5 caves with their ‘i’ IDs. The caves script has a list with a random enemy with the cave id, which is taken from the list of all types of enemies. At the entrance, the cave closes, and in order for it to open, all enemies with the ID of this cave must be killed. For convenience, enemy name = cave id. And here is the problem: the for loop returns only the number 4. I do not understand how and why this happens. The below code is called by the Create() method which is called in the Start() method.
for (int i = 0; i < 5; i++)
{
var cave = Instantiate(caveTemplate, roomPos, Quaternion.identity);
cave.name = i.ToString();
if (i != 0)
{
var enemy = enemiesList[0];
enemy.name = i.ToString();
cave.GetComponent<Cave>().enemies.Add(enemy);
}
}