Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: rechronicle on May 16, 2019, 04:13:45 AM

Title: Simplifying my HealthBar UI FSM?
Post by: rechronicle on May 16, 2019, 04: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.


Any suggestions/ways to write FSM for UI is wanted.
Thank you!
Title: Re: Simplifying my HealthBar UI FSM?
Post by: djaydino on May 16, 2019, 07:46:04 AM
Hi.
Probably by using an array or arrays.

You can use the index as the number.
Title: Re: Simplifying my HealthBar UI FSM?
Post by: rechronicle on May 17, 2019, 09: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.
Title: Re: Simplifying my HealthBar UI FSM?
Post by: Alex Chouls on May 17, 2019, 02:13:59 PM
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...
Title: Re: Simplifying my HealthBar UI FSM?
Post by: rechronicle on May 17, 2019, 09: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!