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 ) the code will be this :
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 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