Triggerable UI is a component that implements logic on a trigger to display a UI Container.
The goal is to open and close a UI Container using a Trigger’s events. The template can be switched from using a trigger’s beginOverlapEvent or interactedEvent to open the UI. It also has the option to lock the player when the UI is open.
Drag the Triggerable UI template into the Hierarchy.
The template has a Trigger object that can be transformed to the specific area that needs to activate the UI.
The template has a UI Container object. Edit the children of this container so it contains the desired UI components. Make sure to not delete the Close Button.
How to use this Template
The root of the template contains 2 custom properties.
If active, the UI will be displayed when the player enters the trigger. If inactive, the UI will be displayed when the player interacts with the trigger.
If true, the player will be unable to move, crouch, or jump when the UI is displayed.
The client script has an Event connected so another script can show or hide the UI.
The syntax for broadcasting the event is as follows:
Events.Broadcast(COMPONENT_ROOT.id .. ".SetUIVisibility", isVisible))Code language: Lua (lua)
See below an example on how to close the UI with the ESC key.
--Seperate client script --Reference to Triggerable UI root object local TRIGGERABLE_UI = script:GetCustomProperty("TriggerableUI"):WaitForObject() function OnEscape(localPlayer, params) -- Prevents Core's default pause from appearing params.openPauseMenu = false --Hide the Triggerable UI Events.Broadcast(TRIGGERABLE_UI.id .. ".SetUIVisibility", false) end -- Intercept the ESC key being pressed Input.escapeHook:Connect(OnEscape)Code language: Lua (lua)