I made a little health bar and stats collection which is reused for different enemies (all the ones needing health bars).
If I make a Game Object in my project folder for my enemy I am only allowed to have components added to that Game Object …so I cannot add my health bar collection to that Game Object. So instead, I assume I have to make a collection for my enemy, so I make a new collection called Enemy and add the health bar. So that’s good. I have prefab now with a health bar. But I also want my enemy to have things other than Collections like a sprite. So I make, in my project folder, a Game Object called EnemyGo then go back to my Enemy collection and add the Game Object. Now I have a Enemy Collection with a health bar collection and a enemy Game Object in it.
This works kinda. I have a script attached to EnemyGO and when the enemy is killed it needs to delete itself. But when I do go.delete(".") it doesn’t delete the health bar. And I don’t know how to reference the collection the game object’s script is on… I don’t think collections are even a thing in runtime. So how do I delete the collection AKA how do I delete the health bar too? I tried go.delete(go.get_parent()) but that doesn’t work.
The reason I’m wanting a prefab is so that I can place many of these Enemy collections on my map and have them all work independently without having to rebuild them for each new entry.
There must be a better way of predefining a prefab…what is it?
Also, if all my enemies are collections then I cannot put them in a folder (aka, game object) in my level so the level entries cannot be organized at all…just a lot of collections.
Any help on the best way to organize and create prefabs which allows this to work would be appreciated! Keep in mind the health bar collection has a few game objects in it for sprites and such.
Thanks!