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);
}
}
↧