using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class CameraController : MonoBehaviour { public Transform cam; public float sensitivity; void Start() { } void Update() { } private Vector2 mouseStartPos = Vector2.zero; private Vector3 cameraStartPos = Vector2.zero; public bool moving = false; public void OnMouseDown(BaseEventData e){ #if UNITY_EDITOR PointerEventData ped = (PointerEventData) e as PointerEventData; mouseStartPos = ped.position; cameraStartPos = cam.transform.position; moving=true; #endif } public void OnMouseUp(BaseEventData e){ #if UNITY_EDITOR PointerEventData ped = (PointerEventData) e as PointerEventData; moving=false; #endif } public void OnMouseMove(BaseEventData e){ #if UNITY_EDITOR PointerEventData ped = (PointerEventData) e as PointerEventData; if(moving){ Vector3 offset = (mouseStartPos-ped.position) * sensitivity; cam.transform.position = cameraStartPos + new Vector3(offset.x,0,offset.y); } #endif } }