| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using UnityEngine;
- public class MMCameraController : MonoBehaviour
- {
- [Header("Camera Settings")]
- public float moveSpeed = 10f;
- public float zoomSpeed = 5f;
- public float minZoom = 2f;
- public float maxZoom = 80f;
- private Camera cam;
- private Vector3 lastMousePosition;
- void Start()
- {
- cam = GetComponent<Camera>();
- if (cam == null)
- cam = Camera.main;
- }
- void Update()
- {
- HandleMovement();
- HandleZoom();
- HandleMouseDrag();
- // Help find ForestRiver tiles
- if (Input.GetKeyDown(KeyCode.F))
- {
- Debug.Log("💡 TIP: Look for blue-green colored tiles - those are ForestRiver tiles where rivers flow through forests!");
- }
- }
- private void HandleMovement()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- Vector3 movement = new Vector3(horizontal, vertical, 0) * moveSpeed * Time.deltaTime;
- transform.Translate(movement);
- }
- private void HandleZoom()
- {
- float scroll = Input.GetAxis("Mouse ScrollWheel");
- if (scroll != 0)
- {
- cam.orthographicSize -= scroll * zoomSpeed;
- cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, minZoom, maxZoom);
- }
- }
- private void HandleMouseDrag()
- {
- if (Input.GetMouseButtonDown(2)) // Middle mouse button
- {
- lastMousePosition = Input.mousePosition;
- }
- if (Input.GetMouseButton(2))
- {
- Vector3 delta = Input.mousePosition - lastMousePosition;
- Vector3 worldDelta = cam.ScreenToWorldPoint(delta) - cam.ScreenToWorldPoint(Vector3.zero);
- transform.position -= worldDelta;
- lastMousePosition = Input.mousePosition;
- }
- }
- }
|