OnPointerEnter - loose image

Hi guys i have my button component with interface IPointerEnterHandler and IPointerExitHandler.

When i point on my button i change its scale to 1.1f but when i do that my button background image disapear and cant figuere out why.

I want both text and image component scale.

Thanks for any help.

    public void OnPointerEnter(PointerEventData eventData)
        {
            thisButton.gameObject.transform.localScale = new Vector2(1.1f,1.1f);
        }
        public void OnPointerExit(PointerEventData eventData)
        {
            thisButton.gameObject.transform.localScale = new Vector2(1.0f, 1.0f);
        }


Never use Vector2 to assign scales.

The reason is because the third term (Z) is zero.

The code above is actually:

new Vector3(1.1f,1.1f,0.0f);   // infinitely thin, hence invisible

When setting scales, you must always write:

new Vector3(1.1f,1.1f,1.0f);   // correct way to scale stuff

ALWAYS use Vector3, and make sure that the Z term is either 1.0f or your scale.

Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy.

3 Likes

That make sense, thanks , resolved.
I was confused because my text scaled as expected only image was lost.

1 Like

Just checking but you asked me to move one of your threads to UGUI but didn’t link me which one. I presume it’s this one? Guess it can stay here now?

Sry i shoul link it to that message t is this one https://forum.unity.com/threads/more-target-graphics-on-one-button-tmpro.1152962/#post-7398767