- Home /
Instantiate with healthbar dont work correctly
I have a problem with duplicating objects. I have enemies who spawn randomly with the amount of hp. The problem is that when there is more than one enemy and I will damage him hp is subtracted from every enemy instead of one. I have a standard hp script (HealthBar with SetMaxHealth and SetHealth attached to a slider and Enemy with maxhealth and currenthealth attached to the enemy). Also my script with spawn:
public class RandomSpawn : MonoBehaviour {
public GameObject myPrefab;
public void Spawn()
{
Vector3 position = new Vector3(Random.Range(10.0f,- 10.0f), -1.55f, 0);
Instantiate(myPrefab, position, Quaternion.identity);
}
}
$$anonymous$$ore info needed.. How is your currenthealth defined (if its static then it will be common with every instance) How do you deter$$anonymous$$e from what prefab instance you reduce the currenthealth and how in practice you do that? Scripts?
Yeap, that was it. I forgot to remove static, Thanks!
Your answer
Follow this Question
Related Questions
How can I do health bar follows enemy? 1 Answer
Healthbar above enemy : 2d 2 Answers
How to create Enemy Health Bar ? 4 Answers