How do I Give all my Enemies Separate Health?

0 favourites
  • 7 posts
From the Asset Store
Health
$18 USD
10% off
Behavior that allows for easy tracking and management of in-game properties such as healthm, mana, stamina, energy etc.
  • I am making a project where there are enemies and you have to shoot them. I have their health above their sprite. But, I only have 1 variable for Enemy Health. I was wondering if there is a way to give all of them separate health, and I don't want to have to create a ton of different variables for each enemy.

  • Do you mean you have different enemy objects? In that case you can make an enemies Family and use a Family variable for health which they all inherit.

  • No, I don't have separate enemy objects. I have a different number of enemies spawn according to another variable. I want them to take damage separately.

  • If you are referring to several instances of the same enemy object then they all have independent health if you gave them an instance variable. What problem are you having?

  • Ok, but I can't see their health above them. When I had the Global Variable, I had a text object set to the Variable so I could see their health. You can't reference Instance Variables in a text object, so I can't actually see their health like I could when I had a Global Variable.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So for the text you use set text to enemy.health

    However the text object needs to relate to the enemy, so you need a condition (unless they are in a Container, this is a different thing). So you can use a condition such as enemy is overlapping text or text is pinned to enemy, some way of linking them together.

    A container is where the enemy and text object are created together so they are always connected kind of like they are part of one large object. This makes picking easier because when you set text to enemy.health it will pick that enemy that was created with it. Check out Containers in the manual if you want to use that method.

  • Ok, it worked! Thank you!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)