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 /
avatar image
0
Question by Paul_aranza · Oct 10, 2015 at 04:38 PM · uicoroutineimagewww

Changing multiple UI.Image source image downloaded via WWW class

Hi, having problem with changing source images for multiple UI.image components.

I have a news Prefab which contains two UI text components and a UI.Image component. I do an api call to a server to get the news articles and parse it through simpleJson. After which I proceeded to create several instances of the prefab.

It all went smoothly for one article. However, When my API returns two or more articles, apparently it just downloads/displays the last image in the images returned by the api.

This is the code I put for filling out the items of the articles:

  foreach (JSONClass article in news.AsArray)
             {
                
                 Transform item = List.GetChild(article["id"].AsInt - 1);
                 StartCoroutine(getImg(article["Pic"], item));
                 print(article["aPic"]);
                 item.FindChild("Title/Text").GetComponent<Text>().text = article["title"];
                 item.FindChild("short/Text").GetComponent<Text>().text = article["Long description"];
 
             }

getImg:

     IEnumerator getImg(string path, Transform someTransform)
     {
         
         form = new WWWForm();
         form.AddField("path", path);
         Debug.Log(form);
        
         www = new WWW(imgURL, form);   
         
         yield return www;
         print("Downloading");
         if (www.isDone)
         {
             if (www.texture != null)
             {
                 
                 sprit = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.zero);
                 someTransform.FindChild("picture").GetComponent<Image>().sprite = sprit;
             }
         }
 
     }

Sample result of my api:

 [
     {
         id: 1,
         title: "asdafss",
         Long description: "sdfasdfas",
         aPic: "uploads/Articles/32701.jpg"
     },
     {
         id: 2,
         title: "sdrasr",
         Long_desc: "asd",
         Pic: "uploads/Articles/22164.jpg"
     },
     {
         id: 3,
         title: "sample3",
         Long description: "lorem",
         Pic: "uploads/Articles/99777.jpg"
      }
 ]
 

As it appears it only loads the last picture for all of the prefabs I instantiated. I do realize this could be due to the coroutine, or maybe I'm missing something. Anyone who have done something similar?

EDIT: I do a post request to my backend which processes the pic path and returns the image I want

Comment
Add comment · Show 1
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 Paul_aranza · Oct 10, 2015 at 01:46 AM 0
Share

And I forgot to mention this would be deployed to android and ios... so anything I should watch out for too?

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

WWW Image Loading Fails When Directory Contains "+" Character 0 Answers

Coroutines and Static function 1 Answer

After upgrading to Unity 2017.2.0p4 UI is darker than it should be 0 Answers

I Have a Button in Canvas, i Click anywhere except the button and it gets clicked 0 Answers

How do I change the size of a UI Image? (Javascript) 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