how is possible in a 2d scene to move different ui images which or on top of each other ?
it is a jigsaw puzzle scene. the ui images are parts of a bigger image and if user move the mouse and click and drag they can put together the images iin order to complete the whole of image.
is any idea how is it possible?
i have a parent as empty gameobject and all ui images are the children of that and also the parent gameobject has a script attached to.
You’ll need to listen for the pointer down and pointer up events in your puzzle piece object.
using UnityEngine;
using UnityEngine.EventSystems;
public class PuzzlePiece : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
private bool _dragging;
public void OnPointerDown(PointerEventData data)
{
_dragging = true;
}
public void OnPointerUp(PointerEventData data)
{
_dragging = false;
}
private void Update()
{
if(_dragging == true)
transform.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
}
}
Here’s a naive solution to get you started. You’ll need to add a lot more logic to make it feel good.