Page 1 of 1
Display Alert until we leave trigger zone
Posted: Fri Jun 01, 2018 11:25 am
by mgregoirelds
Hello,
I would like to know what would be the best way to implement the following case:
I have a GameObject with a component that implement OnTriggerEnter2D() which is calling DialogueManager.ShowAlert(), i.e. a GO that displays "Press A to save". However, I would like the Alert to keep being displayed until the player stays in the Trigger zone. If he leaves the trigger area, I want the Alert to stop being displayed. Same thing if the player does indeed press 'A'.
Is my only solution is to hide the Alert using alpha on the canvas when I leave the trigger zone or press the 'A' button? How do I keep it displaying "forever"?
Re: Display Alert until we leave trigger zone
Posted: Fri Jun 01, 2018 12:53 pm
by Tony Li
Hi,
Here's one way:
1. Set the Alert Trigger's Duration to a very high value such as 99999 -- essentially forever.
2. Add a Dialogue System Trigger set to
On Trigger Exit. Configure its Send Messages action to send the message "HideAlert" to the dialogue UI. If your dialogue UI is in another scene, you can instead write a short script that calls DialogueManager.DialogueUI.HideAlert().
Here's an example scene:
AlertTest_2018-06-01.unitypackage
In the scene, I also added a fake "save" script. When you press 'A', it shows an alert "Saving...", which overrides the "Press A to Save" alert. The GameObject also has a Range Trigger that enables this fake save script only when the player is in the trigger area.
I didn't add a controller. To test the scene, you'll have to manually move the player's transform in the Scene view to make it move in the Game view.
Re: Display Alert until we leave trigger zone
Posted: Fri Jun 01, 2018 2:19 pm
by mgregoirelds
Hello,
I will test this proposed solution and look at the example scene. Thanks!!!
Maybe I could propose for 2.0 a way to display an alert until an OnTriggerExit is called. That could be useful in the case that the player enter a trigger zone and stays in it (while displaying a tutorial message or a command message such as "press on a to save"). Time duration has no real meaning in that case, we only want to display the message until we leave the set area.
Thanks again Tony!
Re: Display Alert until we leave trigger zone
Posted: Fri Jun 01, 2018 3:18 pm
by Tony Li
I'll add that to the list for after the initial 2.0 release. Version 2.0 is being submitted to the Asset Store today.
Re: Display Alert until we leave trigger zone
Posted: Sun Jun 03, 2018 11:06 am
by mgregoirelds
Hello, by the way, your solution worked great! Thanks a lot!
Re: Display Alert until we leave trigger zone
Posted: Sun Jun 03, 2018 11:38 am
by Tony Li
Thanks for letting me know. Glad to help!
Re: Display Alert until we leave trigger zone
Posted: Fri Aug 03, 2018 8:03 am
by Tony Li
Hi Maxime,
In version 2.0.3, if you specify a negative value for an alert's duration, it will stay onscreen forever. You can manually hide it by calling the new HideAlert() Lua function. To do this, you can add a Dialogue System Trigger set to OnTriggerExit, and add a Lua action to trigger that calls HideAlert().