Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
3
Question by Gurunext · Aug 23, 2014 at 10:13 AM · updateimage

Unity 4.6: How to access Image class? Let's say to change sprite with the code.

Well these features are pretty new I would say this is just a bug waiting to be fixed. But it's weird that Image class is shown as "Image (script)". And when in code there is no class Image showing up or maybe I am missing something, maybe there is another way to access this class.

alt text

The puzzle I'm trying to solve is: what's the code to access "source Image"?

image.png (11.5 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
8
Best Answer

Answer by Gurunext · Aug 23, 2014 at 10:24 AM

Ok I was able to quickly answer my own question.

I needed to add this... obviously

 using UnityEngine.UI;

Comment
Add comment · Show 2 · 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 dCalle · Jul 03, 2016 at 05:47 PM 0
Share

you saved my ass, home. Thanks :-*

avatar image beardaintweird · Jan 01, 2017 at 01:13 PM 0
Share

LOL was stuck on this for hours. Clutch man thanks.

avatar image
0

Answer by SoloSebo · Sep 01, 2014 at 11:00 PM

For others that stumble upon this (and still dont get it like me...), here is a little more meat.

 var theImage:UnityEngine.UI.Image; 
 var theSprite:Sprite; //The image you want to drag in the inspector
 
 theImage.sprite = theSprite; //Setting the new image

Hopefully I didn't complicate things.

Comment
Add comment · Show 2 · 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 -JohnMore- · Sep 25, 2014 at 03:10 PM 0
Share

Do you know hot to do it without a reference to the sprite? For example having the sprite name in a string and creating the sprite so you can dynamically change images depending on an object's property?

Something like this:

 Public string ObjectName;
 Public Image ObjectIcon;
 
 void Start()
 {
     ObjectIcon.sprite = new Sprite("ICON_" + ObjectName);
 }
avatar image beardaintweird · Jan 01, 2017 at 01:15 PM 0
Share

The way I set the new image was through accessing the Image's material

var material = AssetDatabase.LoadAssetAtPath(path,typeof($$anonymous$$aterial)) as $$anonymous$$aterial; images[i].GetComponent"<"Image">"().material = material;

Excuse the double quotes around the "<" ">". those and all text inside them would automatically disappear without the ""

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

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Can't update Unity to 3.5.5f3 1 Answer

Unity 4.6: GetComponent().onClick... how do you add an event to button click? 6 Answers

Unity 4.0.1f2 update and script,fbx file errors,. 0 Answers

Wireless updates through internet? 1 Answer


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