Verse Library verse

01 Fragment

Listens to player health changes and dynamically updates a UI widget material color based on health percentages.

verse-library/textures/01-fragment.verse

# Import the necessary Verse libraries
using /Fortnite.com/Devices
using /Engine/Engine

# Define our Main Device. This is the "boss" object in our scene graph.
# It will hold the UI widget and the logic.
device HealthBarController <
    # This is a reference to the UI Widget in our level.
    # Think of it as the "container" for our health bar.
    Widget: WidgetDevice = WidgetDevice()
    
    # This is the Material Instance we created.
    # We need to expose it so Verse can talk to it.
    Material: MaterialInstance = MaterialInstance()
    
    # The player we're tracking.
    Player: Player = Player()
>

# This function runs once when the island starts.
OnBegin<override>()<suspends>: void =
    # Wait for the player to spawn
    Player.SpawnedEvent += () ->
        # Every time the player's health changes, update the bar
        Player.HealthChangedEvent += (new_health: float, max_health: float) ->
            UpdateHealthBar(new_health, max_health)

# The core logic: Update the visual appearance
UpdateHealthBar(current_health: float, max_health: float): void =
    # Calculate percentage (0.0 to 1.0)

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in