Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TouchAndDragControl : MonoBehaviour
  6. {
  7. [SerializeField] LayerMask GUI_Layer;
  8. [SerializeField] bool invertMask;
  9. [SerializeField] Camera MainCam;
  10. [SerializeField] Camera ObjectsCam;
  11.  
  12.  
  13.  
  14. void Update() {
  15.  
  16. if(!(Input.touchCount==0 || Input.GetTouch(0).phase!=TouchPhase.Moved))
  17. {
  18. RaycastHit hitInfo;
  19. Touch touch = Input.GetTouch(0);
  20. Ray ray = ObjectsCam.ScreenPointToRay(touch.position);
  21. if(Physics.Raycast(ray, out hitInfo,1000f,GUI_Layer))
  22. {
  23. RotatableObject targetRot = hitInfo.transform.GetComponent<RotatableObject>();
  24. if(targetRot!=null)
  25. {
  26. Vector3 rot = new Vector3(touch.deltaPosition.y, -touch.deltaPosition.x, 0f);
  27. Rotate(rot, targetRot);
  28. }
  29. }
  30. }
  31.  
  32. }
  33.  
  34. void Rotate(Vector3 rot, RotatableObject target)
  35. {
  36. target.RotateObject(rot.y, -rot.x, 0f);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement