how enable image

Hi guys! I’m completely a beginner of this. I was able to connect multiple images to the canvas. By the script below, i would like to achieve, that a given image show up on the canvas by pressing a given button (e.g. between 0-9 buttons). The problem is that no reference can be found to the images. I would ask some help, to fix the problem with reaching the images by the triggering script. The presented script below was used to perform the trigger. As an example (for better insight to the code) it was made only for one button, but of course it still not works with one button neither.100906-image.jpg

@milhajny
So you want do show a Image when pressing ex: 1 and show another when pressing ex:2 ??

using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour {

	public Image img1;
	public Image img2;

	void Start () {
		// At the start you disable the image 2 and only show the 1
		img1.enabled = true;
		img2.enabled = false;
	}
	
	void Update () {
		// If you press 1 you disable the image 2 and enable the 1
		if (Input.GetKeyDown(KeyCode.Alpha1))
		{
			img1.enabled = true;
			img2.enabled = false;
		}
		// If you press 2 you disable the image 1 and enable the 2
		if (Input.GetKeyDown(KeyCode.Alpha2))
		{
			img1.enabled = false;
			img2.enabled = true;
		}
	}
}

In the inspector you will go and put the Image 1 to the img1 variable and the Image 2 img2 and so on.

Hope it works. Good luck!

Mixery´s answer is already good, but as a beginner as you are it might be overwhelming. Your code basically works with the following change:

public Image image;

instead of:
private Image image.

In Unity itself (the so called) Inspector you drag and drop your image and youre done :slight_smile:

But Mixery´s solution will work too!