I was following Recorded Video Sessions on UI - Unity Learn tutorial to make a draggable panel but I could not get it to work. I am currently using version 5.4.03f of Unity Pro.
I am looking for an explanation of the following behavior:
My Steps:
Create new project 2D
Add Canvas to scene (leave defaults)
Add Panel to Canvas
Create Script called FocusPanel
Add Code
public class FocusPanel : MonoBehaviour, IPointerDownHandler
{
private RectTransform panel;
void Awake()
{
panel = GetComponent();
}
public void OnPointerDown(PointerEventData data)
{
Debug.Log(“Pointer Down!”);
panel.SetAsLastSibling();
}
}
Add script to Panel
Run game
Click on panel
See log (Great!)
Stop game
Hold shift and resize panel to be something like half the original size, in either or both directions (like he does in the tutorial)
Run game
Click on Panel
No log (!What??)
Why does OnPointerDown not get called after I resize the panel?
If I resize the panel back to being just a little smaller than the Canvas it works again, though it seems to fire even if I click on the space outside of the panel. It seems that once the panel is about 2/3 the size of the canvas the event no longer fires.