MMCameraController.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. public class MMCameraController : MonoBehaviour
  3. {
  4. [Header("Camera Settings")]
  5. public float moveSpeed = 10f;
  6. public float zoomSpeed = 5f;
  7. public float minZoom = 2f;
  8. public float maxZoom = 80f;
  9. private Camera cam;
  10. private Vector3 lastMousePosition;
  11. void Start()
  12. {
  13. cam = GetComponent<Camera>();
  14. if (cam == null)
  15. cam = Camera.main;
  16. }
  17. void Update()
  18. {
  19. HandleMovement();
  20. HandleZoom();
  21. HandleMouseDrag();
  22. // Help find ForestRiver tiles
  23. if (Input.GetKeyDown(KeyCode.F))
  24. {
  25. Debug.Log("💡 TIP: Look for blue-green colored tiles - those are ForestRiver tiles where rivers flow through forests!");
  26. }
  27. }
  28. private void HandleMovement()
  29. {
  30. float horizontal = Input.GetAxis("Horizontal");
  31. float vertical = Input.GetAxis("Vertical");
  32. Vector3 movement = new Vector3(horizontal, vertical, 0) * moveSpeed * Time.deltaTime;
  33. transform.Translate(movement);
  34. }
  35. private void HandleZoom()
  36. {
  37. float scroll = Input.GetAxis("Mouse ScrollWheel");
  38. if (scroll != 0)
  39. {
  40. cam.orthographicSize -= scroll * zoomSpeed;
  41. cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, minZoom, maxZoom);
  42. }
  43. }
  44. private void HandleMouseDrag()
  45. {
  46. if (Input.GetMouseButtonDown(2)) // Middle mouse button
  47. {
  48. lastMousePosition = Input.mousePosition;
  49. }
  50. if (Input.GetMouseButton(2))
  51. {
  52. Vector3 delta = Input.mousePosition - lastMousePosition;
  53. Vector3 worldDelta = cam.ScreenToWorldPoint(delta) - cam.ScreenToWorldPoint(Vector3.zero);
  54. transform.position -= worldDelta;
  55. lastMousePosition = Input.mousePosition;
  56. }
  57. }
  58. }