đź§Ľ
Soap - 3.5.1
  • Getting Started
    • What is Soap?
    • Why use Soap?
    • Where to get Soap?
  • Soap Core Assets
    • Scriptable Variable
      • Properties
      • Debugging
      • Variable Reference
      • Runtime Variables
      • FAQ
    • Bindings
    • Scriptable List
      • Properties
      • Callbacks
      • FAQ
    • Scriptable Event
      • Properties
      • Debugging
      • FAQ
    • Event Listener
      • Properties
      • Dynamic Binding
      • FAQ
    • Scriptable Enum
      • Creating new Enum Values
      • Adding Data
    • Scriptable SubAssets
      • Creating/Deleting SubAssets
      • Accessing SubAssets
      • FAQ
    • Scriptable Save
      • Properties
      • FAQ
    • Scriptable Dictionary
      • Properties
      • Callbacks
      • Custom Dictionary Creation
      • FAQ
    • Runtime Injectors
  • Useful Tips
    • Creating Soap ScriptableObjects
      • Soap Asset Creator
      • From Create Shortcut
      • Default Unity Create Menu
    • Using Tags
      • AutoTag Attribute
    • Finding References
    • Editor Fast Play Mode
    • Addressables
      • Solutions
  • Custom Windows
    • Soap Wizard
      • Shortcuts
    • Soap Window
      • Settings
    • Soap Type Creator
    • Soap Asset Creator
  • Quality
    • How to extend Soap?
    • Performance
    • Integration with other assets
    • Games using Soap
    • Suggestions
  • Scene Documentation
    • 1_ScriptableVariables
      • Direct Access
      • OnValueChanged Event
      • Variable Reference
      • Solving Dependencies
      • Saving Variable Values
      • Save Exercise
      • Menu Context Option
    • 2_Bindings
      • BindText/TextMeshPro
      • BindFillingImage
      • BindSlider
      • BindToggle
      • BindGraphicColor
      • BindRendererColor
      • BindComparisonToUnityEvent
      • BindInputField
    • 3_ScriptableLists
      • Adding & Removing Elements
      • Callbacks
      • Auto Clearing
      • Iteration
    • 4_ScriptableEvents
      • Firing Events from code
      • Event Listeners
      • Registering to events from code
      • Firing events from the editor
      • Debugging
    • 5_ScriptableSaves
      • Save Data
      • Useful Methods
      • Save/Load Modes
      • Save Reader
      • Save Manager
      • Save Version
    • 6_ScriptableEnums
      • Scene Setup
      • How does it work?
      • Additional Data
      • Exercise
    • 7_ScriptableSubAssets
      • Scene Setup
      • Direct Reference
      • Indirect Reference
    • 8_RuntimeVariables
      • Manual Injection
      • Flexibility
      • Automatic Injection
    • 9_ScriptableDictionaries
      • Scene Set up
      • Adding & Removing Elements
      • Callbacks
      • Custom Inspector
Powered by GitBook
On this page
  1. Scene Documentation
  2. 4_ScriptableEvents

Event Listeners

4_ScriptableEvent

PreviousFiring Events from codeNextRegistering to events from code

Last updated 8 months ago

Health.cs is where those events are fired, but let’s find out who is listening to these events. Let’s check the prefab_player and examine the DamageVFX.

When the player is damaged, this event is fired and it will trigger the particle system dynamic method “Emit” that takes an int as a parameter. With this simple trick, we can visually show a relation between the amount of damage and the intensity of the VFX without code. A damage of 10 will emit 10 particles, and a damage of 50 , maybe a critical hit, will emit 50 particles.

In a bigger game, you would probably have a different VFX for different amounts of damage, but in Hyper Casual games, you can get away with this. The Heal VFX in the prefab_player does the opposite but works the same way.

You may have noticed that when the player gets damaged, there is a red vignette effect appearing then fading out.

UICanvas/Damage Vignette

As we can see, here we listen to the OnPlayerDamaged event. When it is fired, we activate the Fade out.

Note : we ignore the int parameter as we don’t need it and call a regular method instead of a dynamic method through the unity event.

The example_OnPlayerDeath event is listed by the Game Over screen.

You will notice that the Game Over Screen is visible in the editor and gets disabled when the game starts. Indeed, it needs to be enabled to register to the event at the beginning of the game.

This is what the boolean variable called “Disable after subscribing” is for. The purpose of this variable is to disable the GameObject after subscribing to the event in Awake().

You will notice also that we added a small delay before invoking the response. This is useful to add small delays without needing to write code to do it.