Some conflicts resolved
This commit is contained in:
@@ -1,24 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
<<<<<<< HEAD
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
[RequireComponent(typeof(Collider))]
|
||||
=======
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
>>>>>>> origin/main
|
||||
public class DraggableObject : MonoBehaviour
|
||||
{
|
||||
[Header("Přetahování")]
|
||||
public float dragSmoothness = 15f;
|
||||
|
||||
[Header("Vizuální zpětná vazba")]
|
||||
<<<<<<< HEAD
|
||||
public Renderer Renderer;
|
||||
=======
|
||||
public SpriteRenderer spriteRenderer;
|
||||
>>>>>>> origin/main
|
||||
public Color normalColor = Color.white;
|
||||
public Color dragColor = new Color(1f, 1f, 0.5f);
|
||||
public float scaleOnDrag = 1.15f;
|
||||
|
||||
<<<<<<< HEAD
|
||||
private Rigidbody rb;
|
||||
=======
|
||||
private Rigidbody2D rb;
|
||||
>>>>>>> origin/main
|
||||
private Camera mainCamera;
|
||||
private bool isDragging = false;
|
||||
private Vector3 targetPosition;
|
||||
private Vector3 originalScale;
|
||||
private bool hasBeenScored = false;
|
||||
<<<<<<< HEAD
|
||||
private Plane _dragPlane;
|
||||
private Collider col;
|
||||
|
||||
@@ -30,18 +44,35 @@ public class DraggableObject : MonoBehaviour
|
||||
originalScale = transform.localScale;
|
||||
if (Renderer == null)
|
||||
Renderer = GetComponent<Renderer>();
|
||||
=======
|
||||
|
||||
void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody2D>();
|
||||
mainCamera = Camera.main;
|
||||
originalScale = transform.localScale;
|
||||
|
||||
if (spriteRenderer == null)
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
rb.useGravity = true;
|
||||
rb.constraints = RigidbodyConstraints.FreezeRotation;
|
||||
=======
|
||||
rb.gravityScale = 0f;
|
||||
rb.constraints = RigidbodyConstraints2D.FreezeRotation;
|
||||
>>>>>>> origin/main
|
||||
targetPosition = transform.position;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
HandleInput();
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
@@ -50,10 +81,16 @@ public class DraggableObject : MonoBehaviour
|
||||
Vector3 newPos = Vector3.Lerp(rb.position, targetPosition, Time.fixedDeltaTime * dragSmoothness);
|
||||
rb.MovePosition(newPos);
|
||||
}
|
||||
=======
|
||||
|
||||
if (isDragging)
|
||||
transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * dragSmoothness);
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
|
||||
void HandleInput()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
if (Input.touchCount > 0)
|
||||
{
|
||||
Touch touch = Input.GetTouch(0);
|
||||
@@ -132,15 +169,75 @@ public class DraggableObject : MonoBehaviour
|
||||
if (Renderer != null)
|
||||
{
|
||||
Renderer.material.color = normalColor;
|
||||
=======
|
||||
|
||||
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(); }
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
void TryStartDrag(Vector3 worldPos)
|
||||
{
|
||||
if (GetComponent<Collider2D>().OverlapPoint(worldPos))
|
||||
StartDrag(worldPos);
|
||||
}
|
||||
|
||||
void StartDrag(Vector3 worldPos)
|
||||
{
|
||||
isDragging = true;
|
||||
rb.linearVelocity = Vector2.zero;
|
||||
targetPosition = worldPos;
|
||||
|
||||
transform.localScale = originalScale * scaleOnDrag;
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
spriteRenderer.color = dragColor;
|
||||
spriteRenderer.sortingOrder = 10;
|
||||
}
|
||||
}
|
||||
|
||||
void EndDrag()
|
||||
{
|
||||
isDragging = false;
|
||||
transform.localScale = originalScale;
|
||||
if (spriteRenderer != null)
|
||||
{
|
||||
spriteRenderer.color = normalColor;
|
||||
spriteRenderer.sortingOrder = 0;
|
||||
>>>>>>> origin/main
|
||||
}
|
||||
}
|
||||
|
||||
public void OnScored()
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
Debug.Log("Object scored");
|
||||
if (hasBeenScored) return;
|
||||
hasBeenScored = true;
|
||||
isDragging = false;
|
||||
=======
|
||||
if (hasBeenScored) return;
|
||||
hasBeenScored = true;
|
||||
isDragging = false;
|
||||
|
||||
>>>>>>> origin/main
|
||||
StartCoroutine(SinkIntoHole());
|
||||
}
|
||||
|
||||
@@ -155,12 +252,24 @@ public class DraggableObject : MonoBehaviour
|
||||
elapsed += Time.deltaTime;
|
||||
float t = elapsed / duration;
|
||||
transform.localScale = Vector3.Lerp(startScale, Vector3.zero, t);
|
||||
<<<<<<< HEAD
|
||||
if (Renderer != null)
|
||||
Renderer.material.color = new Color(normalColor.r, normalColor.g, normalColor.b, 1f - t);
|
||||
=======
|
||||
if (spriteRenderer != null)
|
||||
spriteRenderer.color = new Color(normalColor.r, normalColor.g, normalColor.b, 1f - t);
|
||||
>>>>>>> origin/main
|
||||
yield return null;
|
||||
}
|
||||
|
||||
gameObject.SetActive(false);
|
||||
<<<<<<< HEAD
|
||||
LevelManager.Instance?.RegisterItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
|
||||
LevelManager.Instance?.RegisterItem();
|
||||
}
|
||||
}
|
||||
>>>>>>> origin/main
|
||||
|
||||
Reference in New Issue
Block a user