Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TouchAndDragControl : MonoBehaviour
- {
- [SerializeField] LayerMask GUI_Layer;
- [SerializeField] bool invertMask;
- [SerializeField] Camera MainCam;
- [SerializeField] Camera ObjectsCam;
- void Update() {
- if(!(Input.touchCount==0 || Input.GetTouch(0).phase!=TouchPhase.Moved))
- {
- RaycastHit hitInfo;
- Touch touch = Input.GetTouch(0);
- Ray ray = ObjectsCam.ScreenPointToRay(touch.position);
- if(Physics.Raycast(ray, out hitInfo,1000f,GUI_Layer))
- {
- RotatableObject targetRot = hitInfo.transform.GetComponent<RotatableObject>();
- if(targetRot!=null)
- {
- Vector3 rot = new Vector3(touch.deltaPosition.y, -touch.deltaPosition.x, 0f);
- Rotate(rot, targetRot);
- }
- }
- }
- }
- void Rotate(Vector3 rot, RotatableObject target)
- {
- target.RotateObject(rot.y, -rot.x, 0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement