Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Doesn't mouse inputs work on touch anymore?

Discussion in 'Scripting' started by GhulamJewel, Sep 24, 2017.

  1. GhulamJewel

    GhulamJewel

    Joined:
    May 23, 2014
    Posts:
    351
    Hi everyone I have few scripts below that I use in my project they work perfectly fine in the editor on my computer but unfortunately they do not work on my android tablet. Previously I thought OnMouseDown etc works on mobile? Can someone please advise how to make these touch friendly. Thank you.


    Code (CSharp):
    1.     void OnMouseDrag ()
    2.     {
    3.         Vector3 mousePosition = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, 7.00f);
    4.         Vector3 objPosition = Camera.main.ScreenToWorldPoint (mousePosition);
    5.         transform.position = objPosition;
    6.     }
    7. }

    Code (CSharp):
    1.     void Update ()
    2.  
    3.     {
    4.  
    5.  
    6.         if (Input.GetMouseButtonDown (0)) {
    7.          
    8.             RaycastHit hit;
    9.             Vector3 forward = transform.TransformDirection(Vector3.forward) * 500;
    10.             Debug.DrawRay(transform.position, forward, Color.green);
    11.  
    12.             Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    13.  
    14.             if (coll.Raycast (ray, out hit, 100.0F))
    15.             if (hit.collider != null)
    16.      
    17.                 Radius.GetComponent<RadiusControl> ().Target = this.gameObject;
    18.  
    19.         }
    20.     }
    21. }
    Code (CSharp):
    1.     void OnMouseDown ()
    2.     {
    3.  
    4.         Launch.SetActive (false);
    5.         LaunchCursor.SetActive (false);
    6.         Search.SetActive (false);
    7.  
    8.         Bool.GetComponent<LaunchControl>().LaunchToggle = false;
    9.  
    10.  
    11.     }