Jump to content
  • Advertisement
Sign in to follow this  
megabroGames

How to allow the pressing of two "on-screen" buttons simultaneously (Unity UI , Button class, Event Triggers)

Recommended Posts

OK so I have this code working and the methods are being called at the times I'd expected (ie. when the mouse hovers over the button and stops hovering over it)

But when I test it on an Android device, it is not possible to press both buttons at once. The only button that gets pressed is the one where the touch-down happened.

 public class EventHandlerThrust : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 {
 public static EventHandlerThrust instanceOf;

 [HideInInspector] public bool isButtonPressed = false;

 void Start()
 {
     instanceOf = this;

 }

 public void OnPointerEnter(PointerEventData eventData)
 {
     isButtonPressed = true;
     Debug.Log("OnPointerEnter Interfaceyyyy called.");
 }

 public void OnPointerExit(PointerEventData eventData)
 {
     isButtonPressed = false;
     Debug.Log("OnPointerExit Interfaceyyyy called.");
 }
 }

So is it possible to allow the user to press both buttons by holding his thumb over both at the same time, using the Event Trigger System? Or do I have to implement some other kind of Input system?

Share this post


Link to post
Share on other sites
Advertisement
Quote

As far as I know the UI buttons use pointer, which simulates mouse clicks. That's why you cant achieve multi-touch using the default buttons. The UI is intended for menus which usually only take 1 touch at a time.

You need either a complete input system or utilize touch input for mobile devices. Input.GetTouch contains all the information you need about touch input.

You could write an interface for this that captures touch input and maps that to Unity UI but you wont get any hover events for touch as there dosent exists a mouse that could "hover" anything.

I wrote such a touch UI about 2 years ago for Unity when there was the need for a car control stick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!