So I'm having a problem where all my enemies share the same health.
I have a prefab called zombie. When the game first launches a global variable called zombie_health is set to 100.
When a zombie spawns, and i shoot at it, the game will retract -25 from the zombie_health. When zombie_health reaches 0, the zombie will destroy itself
When i spawn more than one zombie, they obviously share this one variable and thus all have the same health and will all die when health reaches 0 - also, shooting any of the zombies will retract health from the variable, so i can have 4 zombies and shoot each of them once and they will all die
I have been messing around with possible solutions for a couple of hours but can't find one that works..
Any of you geniouses have any idea as to how i can spawn a zombie and assign to it a unique health bar, and track damage to that specific zombie?
Right now the tracker is a ray-cast from the bullet that saves object hit as a variable. It then compares the variable with the word "zombie", so it checks if target hit = zombie and if it is, it will do 25 damage to the zombie_health variable
Any help is greatly appriciated.
__________________________________________________________________________________________
A few hours later now, and i've tried giving the zombie prefab a local variable called "my health" and then when 10 zombies are in the game, the bullet would save "object hit" in a variable, which would then trigger an event to that specific zombie to fire it's event "take damage".. But I can't make a send event like that because i can't reference the specific zombie - the "target hit" variable doesn't work =(
There must be a smart solution for this - Am I just too narrow-minded to see it right now?
Any help appriciated - this is doing my head in =(