Page 1 of 1

Calling "OnUse()" from script?

Posted: Wed May 25, 2022 2:47 pm
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!

Re: Calling "OnUse()" from script?

Posted: Wed May 25, 2022 3:07 pm
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