TouchToMouse.cs 423 B

123456789101112131415161718192021
  1. using System;
  2. using UnityEngine;
  3. public class TouchToMouse : MonoBehaviour
  4. {
  5. private void Update()
  6. {
  7. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  8. foreach (Touch touch in Input.touches)
  9. {
  10. RaycastHit raycastHit;
  11. if (Physics.Raycast(ray, out raycastHit))
  12. {
  13. if (touch.phase == TouchPhase.Began)
  14. {
  15. raycastHit.transform.gameObject.SendMessage("OnMouseDown");
  16. }
  17. }
  18. }
  19. }
  20. }