-1
\$\begingroup\$

My canvas contains three buttons and three images. I would like the images to appear when the mouse hovers over buttons.

public GameObject button1;
public GameObject button2;
public GameObject button3;

public Image imag1;
public Image imag2;
public Image imag3;

void Update() {

}

public void OnPointerEnter (PointerEventData eventData) 
{
    Debug.Log ("The cursor entered the selectable UI element.");
}
\$\endgroup\$
0
\$\begingroup\$

If I have understood it correctly all you need to do is following:

NOTE: you don't need code for this.

1): In the editor select the button you want to change the sprite of.

2): Then at your Button component in the inspector set the Transition property to Sprite Swap.

3): Now you will see three extra fields as: Highlighted Sprite(Pointer is on the button), Pressed Sprite(Button is clicked), and Disabled Sprite(button is not interactable).

4): Each of this field require an Sprite so just drag and drop the sprite, you want to show when pointer enters the button space, on the "Highlighted Sprite" field and you have what you wanted.

I hope this will work, I haven't tested it so it may not work. Do let me know if it works or not.

\$\endgroup\$
  • \$\begingroup\$ Maybe you misunderstand me. my point is different. I don't mean the button color or image. I'm talking about a canvas image like background. \$\endgroup\$ – user43474 Oct 20 '16 at 7:25
  • \$\begingroup\$ you want to change the whole background on which buttons are? \$\endgroup\$ – Daniyal Azram Oct 20 '16 at 16:24
  • \$\begingroup\$ we the mouse be ON or ENTER "button1" "imag1" appear. That's all. \$\endgroup\$ – user43474 Oct 20 '16 at 17:06
  • 1
    \$\begingroup\$ Image 1 appears on what? on button? or at the background? your question is not clear you should edit it and add a picture to let others understand it. \$\endgroup\$ – Daniyal Azram Oct 20 '16 at 19:23
  • \$\begingroup\$ Yes, you right. Imag1..2..3 is a background not button image. Sorry for this misunderstanding. \$\endgroup\$ – user43474 Oct 21 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.