- Home /
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:
https://answers.unity.com/questions/547513/how-do-i-detect-when-mouse-passes-over-an-object.html
https://answers.unity.com/questions/783279/46-ui-how-to-detect-mouse-over-on-button.html
https://answers.unity.com/questions/139686/how-to-check-if-player-is-hovering-mouse-over-a-gu.html
https://answers.unity.com/questions/1396456/enlarge-gameobject-when-i-mouse-over-the-specific.html
I have no idea where I went wrong... Any help would be great! Thanks.
Answer by betaFlux · Dec 31, 2018 at 01:18 PM
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;
}
}
Your answer
Follow this Question
Related Questions
Select a game object and perform actions using GUI.Button (EventTrigger) 2 Answers
GUI Follow RaycastHit 2 Answers
Dynamic Alpha Gradient Texture Collision Detection 0 Answers
Drag gui text and drop it on 3d object. 0 Answers
How would I bring up a GUI after a raycast has hit a gameObject with a specific tag? 2 Answers