Search Unity

Input.GetMouseButton works on mobile?

Discussion in 'Scripting' started by gallenwolf, Jul 23, 2014.

  1. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Hello!
    I found out today that Input.GetMouseButton actually works with touches on mobile, specifically, I was testing on a Samsung Galaxy Tab 3. Is it true that the getmouse functions work on mobile, and we don't necessarily need to use Input.GetTouch ?

    EDIT: This is with Unity 4.5.2f1

    Code I was testing with:

    Code (csharp):
    1. usingUnityEngine;
    2. usingSystem.Collections;
    3.  
    4. publicclasstouchTest : MonoBehaviour {
    5.  
    6.  
    7. publicTextMeshmyText;
    8.  
    9. //Updateiscalledonceperframe
    10. voidUpdate () {
    11. if(Input.GetMouseButton(0))
    12. {
    13. myText.text = "Mouse Down";
    14. }
    15. else
    16. {
    17. myText.text = "hello world!";
    18.  
    19. }
    20. }
    21. }
    22.  
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    If Input.simulateMouseWithTouches is true (it is by default), touch input will be translated into mouse input as a side-effect.

    (Documentation needs to be updated. States that this is WSA and WP8 specific, but it isn't).
     
  3. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Ooo, didn't see this before! Thanks for the headsup! Yeah, it definitely works on Android as well. I was getting double clicks because the mouse and touch commands were being triggered together. Have to test on ios. Cheers!
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Can confirm it also works with iOS.

    It's still better to use Input.touches for several reasons (Chief among them, you get more data to work with), but for quick and dirty stuff, you can use the mouse emulation.
     
  5. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
    Awesome! Thanks!
     
  6. jackanewell

    jackanewell

    Joined:
    Jan 27, 2022
    Posts:
    1
    thank god