so I am at the moment creating a prefab… no code yet… just honestly thinking this out…
so I want enemies that are going to be prefabs… and with this prefab script, want to set it like
prefab enemy, go to object 1… if destroyed, look at the next object objective in the arraylist, and go to that object unless that is destroyed… and if not go to it…
should i create an array something like:
[serialization] GameObject[] targetLocation = new GameObjects[]
and within that list, create a function that looks for available first object that isnt destroyed?? has anyone tried this? maybe an example?
something like:
foreach(GameObject target in targetLocations)
{
if(Destroyed(target)
{
go to there Enemy!
}
}
sorry just free handed it, but need to know if this has been done and what or how I can check if object is destroyed in the Array List, or maybe should i put a flag or bool or number to identify to move to next object in the list for the enemy go to?
Instead of an Array use a Collection like a Queue or a Stack or a List. They do support adding and removing entries. So you can simply remove destroyed enemies.
Add the enemies to your collection
Remove the destroyed enemy from the collection
If you insist on using an array then you could just set the destroyed enemy index to null.
Or if you need to retain the reference to destroyed enemies then you could use two lists (targetLocations, destroyedLocations) and whenever an enemy is destroyed you move it from one list to the other.
Or if your enemy has some IAmDestroyed flag then just use that (add one if needed)
As you can see there are lots of ways to approach this. It depends on the needs of your game.
Hey thanks for the reply, i was thinking of using array… but List might be the easy way to go…
so for List enemy
i do want to retain the enemy, which i might just SetActive(False) once he is killed… instead of destroyed, that way, the next level, i can just setActive to true again… not sure if that would be good, or any advice on that? if destroyed, how would i go about bringing them back for the next level… the next level would just be another panel honestly instead of a scene… unless I should do another scene?
I always scene a debat in the past of Scene vs panel vs canvas… but wasnt sure the best way to go about it… and I am expecting to make 60-100 levels… so not sure…
Just make two lists then. Once an enemy gets “killed” move it from on list to the other. At the end of the game you can then enable all the killed enemies and move them back to the original list.