Minimap.cs 826 B

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. namespace SoftMasking.Samples {
  3. public class Minimap : MonoBehaviour {
  4. public RectTransform map;
  5. public RectTransform marker;
  6. [Space]
  7. public float minZoom = 0.8f;
  8. public float maxZoom = 1.4f;
  9. public float zoomStep = 0.2f;
  10. float _zoom = 1.0f;
  11. public void LateUpdate() {
  12. map.anchoredPosition = -marker.anchoredPosition * _zoom;
  13. }
  14. public void ZoomIn() {
  15. _zoom = Clamp(_zoom + zoomStep);
  16. map.localScale = Vector3.one * _zoom;
  17. }
  18. public void ZoomOut() {
  19. _zoom = Clamp(_zoom - zoomStep);
  20. map.localScale = Vector3.one * _zoom;
  21. }
  22. float Clamp(float zoom) {
  23. return Mathf.Clamp(zoom, minZoom, maxZoom);
  24. }
  25. }
  26. }