Page 1 of 1

How to activate proximity selector with touch

Posted: Fri Apr 15, 2022 7:45 pm
by rauljl1
As the title said, i want to activate the proximity selector by touching (android) an actor, for example an NPC instead of useKey or useButton. By the way, I see the Enable touch check, but I can't understand how it works.
Thank you very much for your help!

Re: How to activate proximity selector with touch

Posted: Fri Apr 15, 2022 8:14 pm
by Tony Li
Hi,

There are two ways to activate a Proximity Selector with touch: using the Enable Touch checkbox, or showing a UI button that the player can touch. Neither requires any scripting.

Enable Touch
If you tick Enable Touch, you can set the Touch Area. You can specify an origin (e.g., top left corner of the screen) and an alignment (e.g., align the top left corner of the touch area to the origin). Then set the X & Y offset and the Width & Height. You can specify the X, Y, Width, and Height in absolute pixels or a normalized value 0...1. For example, if you set the Width to normalized with a value of 1, the area will be the entire width of the screen.

When the player touches this area, it will send "OnUse" to the selected Usable.


Show UI Button
Alternatively, you can add a UI Button to the Proximity Selector's canvas (e.g., a copy of the Basic Standard UI Selector Elements instantiated by the Dialogue Manager's Instantiate Prefabs component). Configure the OnSelectedUsable() UnityEvent to activate this button. Configure OnDeselectedUsable() to deactivate it. Configure the button's OnClick() Unity Event to call the ProximitySelector's UseCurrentSelection() method.


BTW, if you don't like either of these options, you can always configure your own interaction system to send "OnUse" to usable objects.

Re: How to activate proximity selector with touch

Posted: Fri Apr 15, 2022 8:35 pm
by rauljl1
Thanks Tony, I solved it by calling the UseCurrentSelection method on a button press on a small canvas wich contains my npc :D .

Re: How to activate proximity selector with touch

Posted: Fri Apr 15, 2022 9:23 pm
by Tony Li
Sounds good! Happy to help.