diff --git a/PuzzleGameProject/Assets/Scripts/PlayerController.cs b/PuzzleGameProject/Assets/Scripts/PlayerController.cs new file mode 100644 index 0000000..800692f --- /dev/null +++ b/PuzzleGameProject/Assets/Scripts/PlayerController.cs @@ -0,0 +1,41 @@ +using UnityEngine; +using UnityEngine.EventSystems; + +public class PlayerController : MonoBehaviour +{ + private Vector3 _lastMousePosition; + private Camera _camera; + private bool _canMove; + + private void Start() { + _camera = Camera.main; + } + + private void Update() { + CheckMovementInput(); + } + + private void CheckMovementInput() { + if (Input.GetMouseButtonDown(0)) + { + _lastMousePosition = Input.mousePosition; + _canMove = !IsMouseOverUI(); + } + + if (!Input.GetMouseButton(0) || !_canMove) return; + + Vector3 mouseWorldPoint = _camera.ScreenToWorldPoint(Input.mousePosition); + Vector3 lastWorldPoint = _camera.ScreenToWorldPoint(_lastMousePosition); + + Vector3 delta = mouseWorldPoint - lastWorldPoint; + + _lastMousePosition = Input.mousePosition; + + _camera.transform.position -= delta; + } + + private bool IsMouseOverUI() { + return EventSystem.current.IsPointerOverGameObject(); + } +} + diff --git a/PuzzleGameProject/Assets/Scripts/PlayerController.cs.meta b/PuzzleGameProject/Assets/Scripts/PlayerController.cs.meta new file mode 100644 index 0000000..8648914 --- /dev/null +++ b/PuzzleGameProject/Assets/Scripts/PlayerController.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 01621b291be214dc6bf7ab90a7cb0d79 \ No newline at end of file