Question by
MainManMike7 · Oct 20, 2018 at 02:47 PM ·
uieventsystemdrag-and-drop
How would I racast at the "OnEndDrag" to see what I hit (I want to parent my button to the slot it hits).
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI;
public class Button : MonoBehaviour , IDragHandler , IEndDragHandler, IBeginDragHandler { public GameObject orignal; Transform origparent; GraphicRaycaster ray; public Vector2 offset;
private void Start()
{
ray = GetComponentInParent<GraphicRaycaster>();
}
public void OnClick()
{
//orignal.transform.position = offset;
//orignal.SetActive(true);
//Destroy(gameObject);
}
public void OnBeginDrag(PointerEventData eventData)
{
origparent = transform.parent;
}
public void OnDrag(PointerEventData eventData)
{
transform.position = Input.mousePosition;
transform.SetParent(GameObject.Find("Inv Canvas").transform);
GameObject.Find("Inv Canvas").GetComponent<CanvasGroup>().blocksRaycasts = false;
}
public void OnEndDrag(PointerEventData eventData)
{
transform.SetParent(origparent);
transform.localPosition = Vector3.zero;
}
}
Comment