Drag and Drop get the slots occupied
How can I get the slots occupied by the dragged gameObget?
For drag and drop, here is the script for drag Gameobjet:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;// using UnityEngine.EventSystems;
public class dragable : MonoBehaviour,IBeginDragHandler,IDragHandler,IEndDragHandler{ public Vector3 positionToReturnTo;
public void OnBeginDrag(PointerEventData eventData){
positionToReturnTo = this.transform.position;
GetComponent<CanvasGroup> ().blocksRaycasts = false;
}
public void OnDrag(PointerEventData eventData){
this.transform.position = eventData.position;
}
public void OnEndDrag(PointerEventData eventData){
GetComponent<CanvasGroup> ().blocksRaycasts = true;
this.transform.position = positionToReturnTo;
}
}
Here is the script for drop zone:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems;
public class Dropzona : MonoBehaviour, IDropHandler { public Image containerImage;
ConfiguracionElectr confscript;
string destino, origen;
public GameObject electron
{
get
{
if (transform.childCount > 0)
{
return transform.GetChild (0).gameObject;
}
return null;
}
}
void Start()
{
confscript = FindObjectOfType<ConfiguracionElectr>();
}
public void OnDrop (PointerEventData eventData)
{
dragable d = eventData.pointerDrag.GetComponent<dragable>();
if (d != null) {
d.positionToReturnTo = this.transform.position;
Comprobar(gameObject.name, eventData.pointerDrag.name);
}
}
Your answer
Follow this Question
Related Questions
UI buttons and drag drop no longer responding 1 Answer
drag and merge object 0 Answers
RectangleContainsScreenPoint works backwards. 0 Answers
2D Drag and Drop, but not when slot is already full 0 Answers
Drag and drop to a specific panel 0 Answers