playMaker
Home
Store
Showcase
Tutorials
Forums
Manual
Wiki
About Us
Playmaker Forum
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Join our
Discord Channel
Home
Help
Search
Login
Register
Playmaker Forum
»
PlayMaker Help & Tips
»
PlayMaker Help
»
Simplifying my HealthBar UI FSM?
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: Simplifying my HealthBar UI FSM? (Read 1365 times)
rechronicle
Full Member
Posts: 119
Mystvaldia
Simplifying my HealthBar UI FSM?
«
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.
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!
Logged
Rechronicle Game Library
djaydino
Administrator
Hero Member
Posts: 7616
Re: Simplifying my HealthBar UI FSM?
«
Reply #1 on:
May 16, 2019, 07:46:04 AM »
Hi.
Probably by using an array or arrays.
You can use the index as the number.
Logged
Join the PlayMaker Discord Channel!
rechronicle
Full Member
Posts: 119
Mystvaldia
Re: Simplifying my HealthBar UI FSM?
«
Reply #2 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.
Logged
Rechronicle Game Library
Alex Chouls
Administrator
Hero Member
Posts: 4000
Official Playmaker Support
Re: Simplifying my HealthBar UI FSM?
«
Reply #3 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...
Logged
rechronicle
Full Member
Posts: 119
Mystvaldia
Re: Simplifying my HealthBar UI FSM?
«
Reply #4 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!
Logged
Rechronicle Game Library
Print
Pages: [
1
]
Go Up
« previous
next »
Playmaker Forum
»
PlayMaker Help & Tips
»
PlayMaker Help
»
Simplifying my HealthBar UI FSM?