Posted By

jquery404 on 08/25/12


Tagged

touch tap Unity


Versions (?)

On Touch Down


 / Published in: C#
 

On Touch down .. attach this script in Main Camera

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class OnTouchDown : MonoBehaviour {
  5.  
  6.  
  7. void Update()
  8. {
  9. // Code for OnMouseDown in the iPhone. Unquote to test.
  10. RaycastHit hit = new RaycastHit();
  11. for (int i = 0; i < Input.touchCount; ++i)
  12. {
  13. if (Input.GetTouch(i).phase.Equals(TouchPhase.Began))
  14. {
  15. // Construct a ray from the current touch coordinates
  16. Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
  17. if (Physics.Raycast(ray, out hit))
  18. {
  19. hit.transform.gameObject.SendMessage("OnMouseDown");
  20. }
  21. }
  22. }
  23. }
  24.  
  25. }

Report this snippet  

You need to login to post a comment.