i’ve seen this script already(Change value one prefab NOT ALL - Questions & Answers - Unity Discussions) which i dont think helps me much because its quite pointless since every single enemy in the game will have 2 hp which is dumb, and it doesnt work for me the way i want to
basically i have a script called EnemyControl
and a global variable:
public static var EnemyHP : float;
i have different prefab enemies sharing the same EnemyHP variable; the damage script work fine with a simple
function OnTriggerEnter (EnemyCollision : Collider)
{
if (EnemyCollision.tag == "Missile")
{
EnemyHP = EnemyHP - Fire.MissileDamage;
}
}
what i want to know is how to increase ONE of the prefab’s EnemyHP when i go to stage2 for per say
So in short, i have for now a flyerEnemy prefab and a zombieEnemy prefab and only want to increase the flyerEnemy’s HP once i reach stage2 knowing they share the same EnemyHP variable.
right, thing is i forgot take out static when i typed it out here, which is why i said the script works fine. i do use the EnemyHP as non static just its the best way for me to use it in other script. But how would i be able to access it in other script(im guessing GetComponent xD) but only change that value for only one prefab which is where im stuck. thx
– leonalchemistWell, you can't change the value in the prefab, but you can change the value in the instantiated object. Just keep track of the objects when creating them var newEnemy : GameObject = Instantiate(your options); You'll want to create a variable for each instantiated enemy, or create an array to hold all of them. Then, as you said, you can use GetComponent on each enemy to get its particular instance of the EnemyControl script and change its individual HP. newEnemy.GetComponent(EnemyControl).EnemyHP = 4;
– Julien-Lyngeumm, i think im better off creating a separate variable HP for each prefab cause i may have something like 300 enemies on the screen at once so i'd have to constantly change the array size and use GetComponent which doesnt sound too performance friendly. i wanted to change the value in the prefab like u said which i cant do, so im better off trying something else, thx though
– leonalchemistIt's much easier if each enemy can keep track of itself!
– syclamothi had one EnemyHP variable, set to every enemy prefab with different HP and its onyl like 2 lines of code and works great too, having to keep track of every single enemyHP on the screen seems hard and doesnt seem like the best way to do it
– leonalchemist