Hi guys, here is my problem.
In order to make an enemy respawn, I’ve got a parent gameobject “Spawner” wich contain a script that instantiate the enemy prefab when the first prefab (he actual enemy stored in a public gameobject of spawner) is missing ( destroyed by player).
The thing is, once the player kills enemy, he’s always missing from the Spawner, and this one instantiate infinity of enemies…So I need to instantiate the newprefab IN the spot that the precedent one used to be in (public gameobject of the spawner script)
You can assign the newly instantiated object to your spawner’s enemy gameobject variable like so:enemyGameObject = GameObject.Instantiate(enemyPrefab);
Hi Goonter, first thanks for your help. I tried this out, (well, a variation of that, using load/resources cause I don’t really know how to access directly a prefab) but I’ve got an error in the console.Here are some images so you guys can have a better understanding of my problem :
There are several problems there. First, don’t use resource load, just make another public game object called “enemy_prefab” or whatever and drop your prefab in to that field in the editor. Next, you need to cast your instaniated object, as it is done in line 25. Add “as GameObject” after the instaniate method. And the reason your waitforseconds doesn’t work is that the need to be in coroutines. See:
Maybe there is something that I miss here but, I have no problem instantiating the prefab, the thing is as my condition to instantiate is pretty much “enemy is destroyed” this condition doesn’t stop to be true once enemy is killed.
Your suggestion doesn’t replace the missing enemy prefab but just create new ones as the destroyed enemy field stay empty.