I am new and dont know a lot yet but i want to know how to “CHANGE AN IMAGE ON BUTTON CLICK” NOT change button image. I have looked every ware and havent found what i need i need to change images on a button click but there are 8 images and 8 buttons. I want one button to change one image and the other buttons change that image i atach to it. ill leave a screen shot.
I want button one to change to image 1 and button two to change to image 2 and so on to 8.
If i get flaged for duplicate fourm it because i could not find a fourm with what i need.
Hi there @donotprikel.
You need to change the SPRITE field in Image component for the current image that you want to show.
I created a similar scenario of your problem and made this:
Created all the buttons that I will need.
Created a single Image game object on canvas.
Created a script called ‘ToggleImage’ that gets the Single Image gameobject on canvas and a image to change.
I attached the script to all buttons and drag the script component to button click event field and select the function that changes the image.
public class ToggleImage : MonoBehaviour
public Image ImageDisplayGameObject;
public Sprite ImageToActive;
public void ShowImage()
ImageDisplayGameObject.sprite = ImageToActive;
Let me know if it helped