Hoow to set image of an imagebox in unity 2d

Hello to everyone :slight_smile:

I have a very simple question to do, I search for some guide, but I don’t found something helpfull for me.This is what I need :

There are 2 (or more) images in a scene, and a button. I want to set the image of the first imagebox as the image of the second imagebox, and reset che image of the first. in visualc# (I know I am a newbie at programming :slight_smile: ) the code will be this :

private void button1_Click(object sender, EventArgs e)

{

image2.BackgroundImage = image1.BackgroundImage;

image1.BackgroundImage = null;

}

I don’t want to import an image from a file.

I see that there is a button OnClick() funtion
57752-immagine.jpg

But I want to set what there is in the image1 and not a fixed resource.
Thanks for the help.

The simple way is importing an limpid image and drag to the Image.sprite.

but also you can write a script like this, and drag this script to the button.

using UnityEngine;
using UnityEngine.UI;

public class resetImage : MonoBehaviour {

    public Image img1, img2;
    
    // Use this for initialization
    void Start()
    {
        Button btn = GameObject.Find("Button").GetComponent<Button>();
        btn.onClick.AddListener(delegate ()
        {
            img1.sprite = img2.sprite;
            img2.sprite = null;
        });
    }
}

Thanks you for your answer, but how I say I am very newbie and I need a some other specifications.

You use img1/img2.sprite, this means that I need manually load an image with the code, there is a possiblity to use an image loaded by project assets ?

Probably is better if I put an image of my test program :slight_smile: How you see, I need to move the image of image1 to the last image and complete the sentence this is an egg. But the image2 can be either A or AN