Forum rules - please read before posting.

Make an object draggable

Hi,

In my template project, I have an object called "Inspect." It displays static information (graphics and text with associated hotspots) in a popup-style view. This object appears when interacting with a hotspot.
I would like to know if it is possible to make this object draggable so it can be repositioned within the view.

Thkx

Comments

  • Is this part of a Menu? If it uses Unity UI, a short custom script should make it draggable.

    Any screenshots you can share will help provide context.

  • No its no part of a men. here some screenshots ok my Inspect component ;

    Inspect object:
    https://ibb.co/7tHQyBhS

    Inspect Inspector:
    https://ibb.co/PsYgzcTW

  • What is your Drag Drop component? A custom script?

    If you move this to a UI Canvas, you can make use of Unity's IDragHandler interface to drag it around with mouse input:

    using UnityEngine;
    using UnityEngine.EventSystems;
    
    [RequireComponent(typeof(UnityEngine.UI.Image))]
    public class DraggableRect : MonoBehaviour, IDragHandler
    {
        private RectTransform rectTransform;
    
        void Awake()
        {
            rectTransform = GetComponent<RectTransform>();
        }
    
        public void OnDrag(PointerEventData eventData)
        {
            RectTransformUtility.ScreenPointToLocalPointInRectangle
            (
                rectTransform.parent as RectTransform,
                eventData.position,
                eventData.pressEventCamera,
                out Vector2 localPoint
            );
    
            rectTransform.localPosition = localPoint;
        }
    }
    
  • Thanks for the help!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.