detect touch input on unity 2D android device


/ Published in: C#
Save to your folder(s)

detect touch input on unity 2D android device


Copy this code and paste it in your HTML
  1. if(Input.touchCount == 1 && Input.GetTouch(0).phase== TouchPhase.Began)
  2. {
  3. Vector3 pos = Camera.main.ScreenToWorldPoint (Input.GetTouch(0).position);
  4. RaycastHit2D hit = Physics2D.Raycast(pos, Vector2.zero);
  5. if (hit != null)// && hit.collider != null)
  6. {
  7. // Debug.Log ("I'm hitting "+hit.collider.name);
  8. status.text = "hit on"+hit.transform.gameObject.name;
  9. }
  10.  
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.