For AI agents: the complete documentation index is available at /AchEngine/en/llms.txt, the full documentation bundle is available at /AchEngine/en/llms-full.txt, and this page is available as Markdown at /AchEngine/en/usage/ui/draggable.md.

Draggable & Touch Objects

AchEngine provides components for dragging and tapping 2D world objects.

Draggable

Derive from Draggable to receive mouse/touch drag events. A missing Physics2DRaycaster is added to the main camera automatically.

public class CardView : Draggable
{
    protected override void Start()
    {
        base.Start();
        OnTouchDown += () => Debug.Log("Picked up");
        OnTouching += position => Debug.Log($"Dragging: {position}");
        OnTouchUp += hits => Debug.Log($"Dropped on {hits.Length} colliders");
    }
}
EventSignatureDescription
OnTouchDownActionPointer pressed
OnTouchingAction<Vector3>Dragging world position
OnTouchUpAction<Collider2D[]>Dropped with overlapping colliders

originalPos stores the world position at the beginning of a drag.

TouchableObject

Override OnTouched() for a tap/click-only object.

public class EnemyObject : TouchableObject
{
    protected override void OnTouched() => Debug.Log("Enemy clicked");
}

ObjectTouchManager

Add one ObjectTouchManager to the scene. It detects left-clicks each frame, raycasts in 2D, and invokes OnTouched() on the hit TouchableObject.