- Home /
Question by
MJG1123 · Mar 26, 2017 at 06:54 PM ·
uidrag-and-dropdragging
Drag and Drop causes oblject to disapear
when I implement this and try to move the object, it disappears off screen`using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems;
%|-560203107_1|% using System.Collections; using System.Collections.Generic; %|1223982083_4|% %|-1558486400_5|%
%|-1546095882_7|% { public void OnBeginDrag(PointerEventData eventData) { Debug.Log("On BEGIN DRAG"); } public void OnDrag (PointerEventData eventData) { Debug.Log("On DRAG"); this.transform.position = eventData.position; } public void OnEndDrag(PointerEventData eventData) { Debug.Log("On END DRAG"); }
%|-219871724_23|% %|-1326688760_24|% }
` this is code from a script in a project back when I had it working in unity 5.2
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
public class DragnDrop : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler {
public GameObject discard;
public GameObject attackPanel;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//Drag and Drop functionality//
//--------------------------//
//---------------------------//
public Transform parentToReturnTo = null;
public void OnBeginDrag(PointerEventData eventData)
{
//Debug.Log ("BeginDrag");
parentToReturnTo = this.transform.parent;
this.transform.SetParent (this.transform.parent.parent);
GetComponent<CanvasGroup> ().blocksRaycasts = false;
discard.SetActive (true);
attackPanel.SetActive (true);
}
public void OnDrag(PointerEventData eventData)
{
//Debug.Log ("Drag");
this.transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
//Debug.Log ("EndDrag");
this.transform.SetParent (parentToReturnTo);
GetComponent<CanvasGroup> ().blocksRaycasts = true;
discard.SetActive (false);
attackPanel.SetActive (false);
}
}
Comment