Unity Changing the button image by clicking
0
Well, I already know that Unity itself has the Sprite Swap function, for that, but I wanted it to click when I changed the image and returned the old one only when it closed the window that was opened, or if I clicked it again on the icon, I tried to several ways so I turned to a help, I'm tempted this way:
void Start()
{
pb = GetComponent<Button>();
}
public void OnPointerEnter(PointerEventData eventData)
{
pb.image.sprite = newSprite; ;
Debug.Log("Mouse Enter");
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("Mouse Exit");
//Change Image back to default?
},Well, I already know that Unity itself has the Sprite Swap function, for that, but I wanted it to click when I changed the image and returned the old one only when it closed the window that was opened, or if I clicked it again on the icon, I tried to several ways so I turned to a help, I'm tempted this way:
void Start()
{
pb = GetComponent<Button>();
}
public void OnPointerEnter(PointerEventData eventData)
{
pb.image.sprite = newSprite; ;
Debug.Log("Mouse Enter");
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("Mouse Exit");
//Change Image back to default?
}
}
Comment
Your answer
Follow this Question
Related Questions
switch between 5 Ui icons by pressing a button 0 Answers
Shooting an instantiated missile the way a object is facing. 0 Answers
How do I make a scrollbar for the camera? 0 Answers
How to add more UI elements to Dropdown OptionData except default string and sprite values in Unity? 0 Answers
Find nearest enemy object in radius 2 Answers