Calling "OnUse()" from script?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
maxvsthegames
Posts: 20
Joined: Sun Apr 04, 2021 11:54 am

Calling "OnUse()" from script?

Post by maxvsthegames »

Hi,

I'm working on some touch control for my game and I wanted to make a button on screen that would basically trigger the "OnUse()" fonction to interact with objects (opening doors, treasure, etc).

I tried simply calling ProximitySelector.UseCurrentSelection() when clicking on the button, but for some reason I get an error and found out that the 'currentUsable' variable is null. What's weird is that if I make a debug.log in ProximitySelector's Update method to write the value of currentUsable in the console, I see that it's not null.

The OnUse() works when I use the keyboard key, but won't work when I try calling it with a button on screen. Can you help me with this? Thanks!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Calling "OnUse()" from script?

Post by Tony Li »

Hi,

Can you configure your UI button to call the Dialogue System Trigger's OnUse() method directly?

If you only want to show the UI button when the player is near the Dialogue System Trigger, you can add a trigger collider and Trigger Event to the Dialogue System Trigger GameObject. Configure the Trigger Event's OnTriggerEnter() UnityEvent to show the UI button and OnTriggerExit() UnityEvent to hide it.

If you want to use ProximitySelector, then as a debugging step make sure the selector UI is visible when you press the UI button. I don't know why that error would be reported. If you can't identify the issue, please feel free to send a reproduction project to tony (at) pixelcrushers.com
Post Reply