dominiku pomoc

This commit is contained in:
2026-04-26 10:04:37 +02:00
parent 0a163b2a1e
commit 74fa735322
6 changed files with 5437 additions and 77 deletions

View File

@@ -25,7 +25,6 @@ public class DraggableObject : MonoBehaviour
rb = GetComponent<Rigidbody2D>();
mainCamera = Camera.main;
originalScale = transform.localScale;
if (spriteRenderer == null)
spriteRenderer = GetComponent<SpriteRenderer>();
}
@@ -40,33 +39,38 @@ public class DraggableObject : MonoBehaviour
void Update()
{
HandleInput();
if (isDragging)
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * dragSmoothness);
}
void HandleInput()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
Vector3 worldPos = mainCamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10f));
if (touch.phase == TouchPhase.Began) TryStartDrag(worldPos);
else if (touch.phase == TouchPhase.Moved ||
touch.phase == TouchPhase.Stationary) { if (isDragging) targetPosition = worldPos; }
else if (touch.phase == TouchPhase.Ended ||
touch.phase == TouchPhase.Canceled) { if (isDragging) EndDrag(); }
if (touch.phase == TouchPhase.Began)
TryStartDrag(worldPos);
else if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)
{
if (isDragging) targetPosition = worldPos;
}
else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
{
if (isDragging) EndDrag();
}
}
// na twest pro myŠ
else
{
Vector3 worldPos = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f));
if (Input.GetMouseButtonDown(0)) TryStartDrag(worldPos);
else if (Input.GetMouseButton(0) && isDragging) targetPosition = worldPos;
else if (Input.GetMouseButtonUp(0) && isDragging) EndDrag();
if (Input.GetMouseButtonDown(0))
TryStartDrag(worldPos);
else if (Input.GetMouseButton(0) && isDragging)
targetPosition = worldPos;
else if (Input.GetMouseButtonUp(0) && isDragging)
EndDrag();
}
}
@@ -81,7 +85,6 @@ public class DraggableObject : MonoBehaviour
isDragging = true;
rb.linearVelocity = Vector2.zero;
targetPosition = worldPos;
transform.localScale = originalScale * scaleOnDrag;
if (spriteRenderer != null)
{
@@ -106,7 +109,6 @@ public class DraggableObject : MonoBehaviour
if (hasBeenScored) return;
hasBeenScored = true;
isDragging = false;
StartCoroutine(SinkIntoHole());
}
@@ -127,7 +129,6 @@ public class DraggableObject : MonoBehaviour
}
gameObject.SetActive(false);
LevelManager.Instance?.RegisterItem();
}
}
}