How do I spawn prefab object with script attached to it?

I’m trying to spawn enemy object which I made prefab of it as well. The thing is, I removed whatever is in the scene and trying to spawn using prefab on EnemyManager from Unity Survival Shooter tutorial.
The only difference between theirs and mine is that my enemy spawner requires Player object to follow and have it attached as part of script.

It does spawn, but the script(s) that are attached to it is not working at all. All it does is piling upon previously spawned objects. (script works fine with original object placed in the scene, but I want them to be keep spawning even when original is destroyed. Which is why I’m trying to use prefabs)

82225-chasejs-drone-prefab.jpg

Whenever I try to drag and drop FPSController on the script attached to prefab object, Unity won’t allow me to do that. So I tried to prefab everything I need for chase script, but when it is spawned, like I said above, they do nothing and just sit there.

How do I spawn object with scripts attached to it and make them work (i.e. follow the player) once it is spawned using prefab?

Or, is there way to spawn object without using prefabs and still have it working even if original object is destroyed? (so not instantiate for sure)

You want to use Object Pooling. It’s a technique used for creating many game objects and then re-using them instead of destroying them. If you use this method your game will run smoother. You will find you can also reference your player object in the Object Pooling class. Therefore your enemies could gain access to player variables such as position ect as they will both exist in the same place. Unity has a tutorial to get you started with Object Pooling link text This is probably more work than you wanted or expected, but it’ll pay off if you persevere

Hope that helps.