- Home /
how can i drag and drop a box of type text?
Im trying to drag and drop a text box. like organizing words in a way that they can form a sentence. But i cant do it properly, when i try to drag the box it just disapears.. im programing in C# in Unity 5.2.1f1 can anyone help me?
the code that i made: using UnityEngine; using System.Collections; using UnityEngine.EventSystems;
public class DragHandler : MonoBehaviour, IBeginDragHandler , IDragHandler , IEndDragHandler {
public static GameObject itemBeginDragged;
Vector3 startPosition;
Transform startParent;
#region IBeginDragHandler implementation
public void OnBeginDrag (PointerEventData eventData)
{
itemBeginDragged = gameObject;
startPosition = transform.position;
startParent = transform.parent;
GetComponent<CanvasGroup> ().blocksRaycasts = false;
}
#endregion
#region IDragHandler implementation
public void OnDrag (PointerEventData eventData)
{
transform.position = Input.mousePosition;
}
#endregion
#region IEndDragHandler implementation
public void OnEndDrag (PointerEventData eventData)
{
itemBeginDragged = null;
GetComponent<CanvasGroup> ().blocksRaycasts = true;
if(transform.parent != startParent)
transform.position = startPosition;
}
#endregion
} and in atatch what i need to do in the scene organize those word there..
Your answer
Follow this Question
Related Questions
3D Drag&Drop with collision 0 Answers
How do I detect OnDrop event on a GameObject? 0 Answers
Unable access the location of the cloud builds and the asset bundles 0 Answers
Unity virtual joystick - jarring movement 0 Answers
cant pickup object more than 1 0 Answers