Enlarge GameObject in GUI panel when MouseOver

I’m trying to create a card game prototype.

Once I have cards in my hand (a GUI panel), I would like to hover over the card with my Cursor and have it enlarge.

Current setup: -Cavas -Panel (for the deck) -Panel (for my hand)

When a card is drawn, it is initially a child of the deck panel, moves to the hand panel, and becomes a child of that panel.

None of what I have tried works:

I have tried using Raycasts, the OnMouseEnter() & OnMouseOver(). I have tried an EventSystem: Event.current.mousePosition & EventSystem.current.IsPointerOverGameObject()
I have tried both 2D and 3D box colliders with all methods.

Resources I have tried:

I have no idea where I went wrong…
Any help would be great!
Thanks.

1 Answer

1

This is what I use for this case. Just attach it to your cards:

public class UIOnHoverEvent : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {

    Vector3 cachedScale;

    void Start() {

        cachedScale = transform.localScale;
    }

    public void OnPointerEnter(PointerEventData eventData) {

        transform.localScale = new Vector3(1.5f, 1.5f, 1.5f);
    }

    public void OnPointerExit(PointerEventData eventData) {

        transform.localScale = cachedScale;
    }
}

Thank you :)