BindComparisonToUnityEvent
2_Bindings
Last updated
2_Bindings
Last updated
This one is a bit trickier but is the most useful. Find the Game Over Screen.
You can see that there are 2 BindComparisonToUnityEvent components on this panel.
Now enter play mode and set the health to 0 using the health slider. Then, once the game over panel appears, set the health back to 100.
It might seem a bit overwhelming at first, but it is simple. Here is what happens:
The first component (1) does the following:
Binds itself to example_float_currentHealth variable.
Checks if the variable value is smaller or equal to 0 (when it changes).
If true, triggers the unity event. In this case -> enable the gameObject.
The second component (2) does the following:
Binds itself to example_float_currentHealth variable.
Checks if the variable value is bigger to 0 (when it changes).
If true, triggers the unity event. In this case -> disable the gameObject.
This check happens also on Start(), to make sure the conditions are validated at the start of the game (in this case the game over screen will be hidden as the health is set to 100).
This is useful for menus, pop ups, VFX and other stuff when you don’t want to make a script to handle simple behaviors.
Many things can be resolved with Unity Events. I recommend using unity events for visuals feedback and juice and not for actual game logic. You can consider them as “hooks” where you can attach nonessential things to your game.
Note: Unity events creates more garbage than traditional C# events, so they are not the most performant. However, I have used them in mobile games and so far, never had an issue with them.