many objects with same script

I have an enemy script, which has the enemy health, ai and everything in one script. I made the script so that it would be easy to customize the enemy, thats the reason they are in the same script.
Unfortunately I have run into a problem when trying to make multiple enemies to my scene.
My script works like this: if life goes to 0, then variable “dead” is true, which triggers a function which deletes the enemy gameObject.
The problem with it is that whenever one enemy is deleted all of them are deleted. They all have same script attached to them and they all have same tag.

To solve that I tried destroying the enemy from another script. So the other script checks if the varialbe dead is true, and if it is then deletes target.gameObject.
This however doesn´t really solve the problem. I does prevent killing all of the enemies at once, but whenever one of the enemies is killed all of the others die with 1 shot even though it should take much more.

So I´m asking do the scripts with same name interact somehow? so when one script returns “dead = true”, then all scripts return “dead = true”?
And most of all I would like to know how to solve it, so that I could have many enemies.

hopes up, Siim

You should be able to do what you are talking about.

To properly help you fix the problem you are going to have to post some of your code though. The function that deletes the gameobject is probably a good place to start. If you are deleting by tag, that might be your problem right there.

No, each script has its own “dead” variable. The only way that setting one to true would make all of them true was if it’s a static variable, which is generally why you shouldn’t use static variables unless you know for sure there will only ever be one instance.

–Eric

I thought it couldn´t be that all scripts interact that way, also I can´t really understand how could I be so stupid and set “dead” to a static variable o.O, probably just a typo, because there was no need for it to be static. Changing that to private solved the problem.