- Home /
How to load enemies according to enemy list?
I have a game scene, but with different levels. I have many enemy prefabs for the entire game, for example, I have 30 different enemy prefabs.
Now what I want to do is: I load this scene, but with different level information, which contains different enemy informations, for example, only 10 of the enemy prefabs will be used in this level. How to do this? or how to design the level information?
One approch is using Resources.Load, but I'm not sure if this is the best way to do this.
@NeverHopeless, It would be better if u can provide some links. I searched about xml serialization on msdn. I understood that concept, but I am not able to implement yet. So, I just made levels as prefabs, and store it under Resources folder and load specific prefab whenever necessary. But, this case only works, when entire level have static objects like in my current game. There are no enemies, no obstacles, it contains only blocks in certain pattern so I don't need to worry about spawning an enemies in dynamic way during runtime.
What I do, when all levels has more properties like obstacle positions, enemy spawner locations, etc. I wanna choose dynamic way.
Answer by NeverHopeless · Aug 06, 2015 at 11:33 AM
IMHO, you should prepare xml files for level settings, load xml file for the current level and based on values in it, gather relevant data. e.g.,
SettingsLevel1.xml:
<LevelSettings>
<EnemyList>
<Enemy>
EnemyPrefab1
<Enemy>
<Enemy>
EnemyPrefab2
<Enemy>
....
</EnemyList>
<LevelSounds>
<BackgroundSound>
BackgroundMusicLevel1.mp3
</BackgroundSound>
<GunSound>
GunSoundLevel1.mp3
</GunSound>
</LevelSounds>
....
</LevelSettings>
Now based on the values, you can then load stuff from resources folder dynamically.