Question by
Munvik · May 05, 2019 at 05:36 PM ·
raycastraycastingdrag-and-drop
GraphicRaycaster.Raycast doesnt work properly while executing OnEndDrag(...)
Hey. My problem depends on not properly Raycasting UI.
public void OnEndDrag(PointerEventData eventData)
{
//Code to be place in a MonoBehaviour with a GraphicRaycaster component
GraphicRaycaster gr = this.GetComponent<GraphicRaycaster>();
//Create the PointerEventData with null for the EventSystem
PointerEventData ped = new PointerEventData(null);
//Set required parameters, in this case, mouse position
ped.position = Input.mousePosition;
//Create list to receive all results
List<RaycastResult> results = new List<RaycastResult>();
//Raycast it
gr.Raycast(ped, results);
foreach (RaycastResult result in results)
{
Debug.Log("Hit " + result.gameObject.name);
}
GameObject panel = transform.Find("Panel").gameObject;
if (panel)
panel.transform.localPosition = Vector3.zero;
}
It raycasts only 1 gameobject,that one which i drag. For example if I drag BP Slot (1) and drop on BP Slot(2) it raycasts only BP Slot (1). I want to make Inventory with drag and drop system.
Strange fact is while im execute that code in void Update() it raycasts properly.. What is going on ?
problem.jpg
(228.9 kB)
problem.jpg
(228.9 kB)
Comment
Answer by Munvik · May 05, 2019 at 07:36 PM
Ok, SOLVED I deleted GraphicRaycaster from BP Slots and RaycastTarget from Panel (BP Slot's child).