So I wrote some code that’s supposed to spawn a certain number of enemies after changing scene. I have verified that:
- the list containing what to spawn stays the same
- the spawner object does change scenes correctly
- the different objects from which I get the list work correctly (as in they do provide the required information I ask of them)
- I have the right “using” directories (system, unityEngine.SceneManagement, etc)
Here is the code:
public class Battle : MonoBehaviour
{
public Vector3[] SpawnSpots;
public bool startBattle;
public int enemyAmount;
public string encounterType;
public GameObject[] Enemies;
void Awake()
{
DontDestroyOnLoad(gameObject);
}
void Update()
{
// detecting if Jesus started a battle
if (startBattle)
{
// detecting what kind of battle it is
if(encounterType == "demonic")
{
Enemies = gameObject.GetComponent<BattleList>().demonicEnemies;
}
else
{
Debug.Log("Wrong battle type");
}
// actually activating the battle mechanisms
SceneManager.LoadScene(1);
startBattle = false;
spawnEnemies();
}
}
void spawnEnemies()
{
// loop for spawning the enemies
for(int i = 0; i < enemyAmount; i++)
{
Instantiate(Enemies[0], SpawnSpots*, Quaternion.identity);*
}
}
}