Display Alert until we leave trigger zone

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
mgregoirelds
Posts: 106
Joined: Wed Aug 23, 2017 4:10 pm
Location: Canada

Display Alert until we leave trigger zone

Post 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"?
Unity 2022.3.17f1
Dialogue System 2.2.44.1
OpenAI Addon 1.0.12
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Display Alert until we leave trigger zone

Post 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.
mgregoirelds
Posts: 106
Joined: Wed Aug 23, 2017 4:10 pm
Location: Canada

Re: Display Alert until we leave trigger zone

Post 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!
Unity 2022.3.17f1
Dialogue System 2.2.44.1
OpenAI Addon 1.0.12
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Display Alert until we leave trigger zone

Post 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.
mgregoirelds
Posts: 106
Joined: Wed Aug 23, 2017 4:10 pm
Location: Canada

Re: Display Alert until we leave trigger zone

Post by mgregoirelds »

Hello, by the way, your solution worked great! Thanks a lot!
Unity 2022.3.17f1
Dialogue System 2.2.44.1
OpenAI Addon 1.0.12
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Display Alert until we leave trigger zone

Post by Tony Li »

Thanks for letting me know. Glad to help!
User avatar
Tony Li
Posts: 22057
Joined: Thu Jul 18, 2013 1:27 pm

Re: Display Alert until we leave trigger zone

Post 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().
Post Reply