Search Unity

The Button in the middle activates if i press two side of the button.

Discussion in 'Scripting' started by bekiryanik, Sep 20, 2014.

  1. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Hello,


    Like in the topic, that is my issue. If i press "1" and "2" buttons at the same time, "SELECT" button activates. How can i prevent this?

    Thanks.
     
  2. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Which button would you like to activate the select button 1 or 2?
    Can you post your code?
     
  3. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Select button runs if i press 1 and 2 buttons at the same time. I don't want the select button run. It happens in android device. It is in the middle of the screen and if i press two side of it( on 1 and 2), it runs. I need to prevent this.
     
  4. kodagames

    kodagames

    Joined:
    Jul 8, 2009
    Posts:
    548
    Ok wheres your code, so I can possibly help you.
     
  5. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Here is my codes.

    Code (CSharp):
    1.    
    2.     if (GUI.Button (selCharacter.rect, "", skin.GetStyle("selectCharacter")))
    3.     {
    4.     //
    5.     }
    6.     if (GUI.Button (nextB.rect, "", skin.GetStyle("nextButton")))
    7.     {
    8.     //
    9.     }
    10.    
    11.     if (GUI.Button (backB.rect, "", skin.GetStyle("backButton")))
    12.     {
    13.     //
    14.     }
    15.  
    16.  
    Thank you!
     
  6. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Anyone knows how to solve this problem?
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    The suite of GUI functions are mouse-oriented, so on a multi-touch screen, they take the "average" of the touches present onscreen and only see a single touch.

    To get around this, break your check for the buttons into two parts, using the identical rectangles:

    1. inside OnGUI(), draw the buttons, but do so with GUI.DrawTexture(), not GUI.Button(). Do not check the return code of GUI.DrawTexture(); it is void.

    2. inside your Update() function, iterate over the Input.touches array and check each individual touch to see if it went down inside the rectangle of each of the three buttons.

    That way you will be able to tell when someone touches 1 and 2, but NOT the button in the middle.

    Again, do not use the GUI.Button() function inside of OnGUI(), but rather check it explicitly (using the same predetermined rectangles) in the Update() function.

    The only extra thing here is if you want it to ALSO work with mouse (on desktop), you need to iterate the mouse touch in addition to each of the touches[] array.

    Kurt
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Try setting Input.simulateMouseWithTouches to false. The docs say it only applies to Windows/WP, but the docs have been wrong before and it does appear that it's trying to simulate the mouse by averaging the two touch locations.
     
  9. bekiryanik

    bekiryanik

    Joined:
    Jul 6, 2014
    Posts:
    191
    Thanks guys! By your answer i solved the problem.