Search Unity

Problems with buttons and multiTouch

Discussion in 'iOS and tvOS' started by bergerbytes, Feb 6, 2010.

  1. bergerbytes

    bergerbytes

    Guest

    So I know the iphone can read 5 fingers at once but I am having trouble getting unity to properly read touches when there is a second finger on the screen.

    For example, If I have a dual stick game and a pause button in the top right if I have one finger on a joystick and try to push pause it doesn't work. But if I just tap the pause button with no other fingers on the screen it works.

    Thanks,
    -Mike
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Unity properly detects multitouch if you use the iPhoneInput class.

    OnGUI does not support multitouch, its pure single touch, so you can't have more than one gui touched at a time
    But you likely also wouldn't use it for ingame gui anyway as it will cost you significant performance. Use the GUIManager (1 or 2) or SpriteUI for ingame guis
     
  3. bergerbytes

    bergerbytes

    Guest

    Hmm.. So ,
    Code (csharp):
    1.  
    2. iPhoneInput.touches[0].position
    3.  
    Would be what I'm looking for? How would I use it? Think you could point me in the right direction? Most of the stuff I've looked at has been pretty complex.

    Thanks,
    Mike
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    The position of the touch is reported in screen coordinates. You can draw a button image using GUI.DrawTexture and then test if the touch is in its rectangle using Rect.Contains:-
    Code (csharp):
    1. var buttonRect: Rect;
    2.    ...
    3. GUI.DrawTexture(buttonRect, buttonImage);
    4.  
    5. if (buttonRect.Contains(iPhoneInput.touches[0])) {
    6.     // Button action.
    7. }
     
  5. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    Thanks a lot Andeee.. I was searching for the similar kind of post.. i was almost ther to post one asking the same thing... but i got this.. thanks a lot for the guidence..
     
  6. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    here i am now facing a problem with version. I am using iphone Unity 1.7 Indi version for development and is this error bcos of the same reason ?? could u help me in fixing this...

     
  7. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Rect.Contains expects a Vector2 parameter. You need to pass in touches[0].position rather than just the touch object itself.