Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Durlo · Nov 09, 2015 at 07:03 AM · unity 2dimages

Hoow to set image of an imagebox in unity 2d

Hello to everyone :)

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 :

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 alt text

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

immagine.jpg (22.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by say_forever · Nov 09, 2015 at 08:06 AM

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;
         });
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Durlo · Nov 09, 2015 at 12:35 PM

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 ANalt text


immagine.jpg (189.7 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image say_forever · Nov 12, 2015 at 12:19 PM 0
Share

you create a folder named Resources below Assets and use following code to load and assign image.

Texture texture = Resources.Load("filename"); img.texture = texture;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to add a picture 0 Answers

How can I change one canvas image to another? 1 Answer

Movement Animation Looping when it Shouldn't 0 Answers

I Can not start my project from Unity Hub... 1 Answer

When cloned from GitHub Scene is empty but the assets are still there. ,When cloned from GitHub Scene is empty but the assets are still there. 2019.3.0f6 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges