playMaker

Author Topic: Simplifying my HealthBar UI FSM?  (Read 256 times)

rechronicle

  • Junior Playmaker
  • **
  • Posts: 56
  • Medievaliant
    • View Profile
    • Indie RPG Creator
Simplifying my HealthBar UI FSM?
« on: May 16, 2019, 01:13:45 AM »
Hello,
I have questions regarding my health UI which I think is a bit complicated if I keep going. You can see the FSM in the attachment.

  • I make a check/test if it is equal/less/greater to 3 or 2 or 1 and show Health(UI Image) based on it.
    It only has 3 health bar right now, so it's still manageable, but then I think it will be a spaghetti if I got 10+ health or so.
    How to simplify this?
  • Which one is a good practice, check the health variable change every frame or send a global event every time there's an update to UI visual?

Any suggestions/ways to write FSM for UI is wanted.
Thank you!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4518
    • View Profile
    • jinxtergames
Re: Simplifying my HealthBar UI FSM?
« Reply #1 on: May 16, 2019, 04:46:04 AM »
Hi.
Probably by using an array or arrays.

You can use the index as the number.
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

rechronicle

  • Junior Playmaker
  • **
  • Posts: 56
  • Medievaliant
    • View Profile
    • Indie RPG Creator
Re: Simplifying my HealthBar UI FSM?
« Reply #2 on: May 17, 2019, 06:37:32 AM »
Hey there,
thank you for mentioning array.
I never thought to use the array like that up until now.

I'm interested to know many possibilities in using an array, if there any.
It's hard to search, even in the Unity forum.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3632
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Simplifying my HealthBar UI FSM?
« Reply #3 on: May 17, 2019, 11:13:59 AM »
I would use a UI Panel with a Grid Layout Group component.
Add the maximum number of hearts as children of this panel.
This gives you a nice hearts panel that can be easily tweaked.

Then add an FSM to the Hearts panel.
The FSM has an Int variable for the current health (number of hearts).
It responds to global events Add Heart and Lose Heart.

Add Heart:
Increment the current health by 1 and use Get Child Num and Activate Game Object to activate that heart.

Lose Heart:
Use Get Child Num and Activate Game Object to de-activate the current heart. Decrement the current health by 1.

This is just one way to do it but seems flexible and only uses one variable and 2 actions. Of course, you'll also need to check for hearts hitting zero or max number.

I'll try to make a quick sample if you need more help setting this up...

rechronicle

  • Junior Playmaker
  • **
  • Posts: 56
  • Medievaliant
    • View Profile
    • Indie RPG Creator
Re: Simplifying my HealthBar UI FSM?
« Reply #4 on: May 17, 2019, 06:13:44 PM »
Hello,
I think I can't get it right with the Panel and Grid Layout component. The UI Image keeps getting stuck in the corner.

I'll try some more, but a Unity sample package would help a lot too.
Thank you!