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
0
Question by SuperMasterBlasterLaser · May 19, 2014 at 01:58 PM · buildspriteserverwwwcreate a texture

Image is streched after downloading from server

Hello.

I have C# code that donwloads pictures from server and shows them:

     IEnumerator downloadImg (string url)
     {
         Texture2D texture = new Texture2D(1, 1, TextureFormat.DXT1, false);
         WWW www = new WWW(url);
         yield return www;
         www.LoadImageIntoTexture(texture);
 
         Sprite image = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
         renderer.sprite = image;
     }

In my editor it shows the result like this: alt text

But when I build to web, it shows this like that: alt text

(Don't mind background) Looks like it streching image. However the size of images remains same, I do not understand why.

What I need to add in my C# code to show it exacly like in Editor?

P.S Max resolution of images are 263 x 163

2.jpg (63.9 kB)
1.jpg (121.9 kB)
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 SuperMasterBlasterLaser · May 20, 2014 at 06:52 AM 0
Share

Please help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Xumbu · May 20, 2014 at 06:03 PM

instead of sprite you could use OnGUI() and GUI.DrawTexture()

 GUI.DrawTexture(rect, image, ScaleMode.ScaleToFit, true);


Comment
Add comment · Show 3 · 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 SuperMasterBlasterLaser · May 21, 2014 at 06:11 AM 0
Share

Is there some kind of scale mode for Sprite?

avatar image Xumbu · May 21, 2014 at 09:10 PM 0
Share

no i don't think so. actually Sprites should "scale to fit" by default.

I don't no why it does not work with your images. Seems to be a bug

avatar image SuperMasterBlasterLaser · May 22, 2014 at 05:10 AM 0
Share

I have used your advice and wrote this:

 void OnGUI() {
         GUI.depth = 10;
         if (isDownloaded) {
             renderer.sprite = null;
             Vector3 myScreenPosition = Camera.main.WorldToScreenPoint(this.transform.position);
             Vector2 myPosition = new Vector2();
             myPosition.x = myScreenPosition.x;
             myPosition.y = myScreenPosition.y;
             //guiPosition.x - 100, guiPosition.y - 350
             //Vector2 guiPosition = GUIUtility.ScreenToGUIPoint(myPosition);
             GUI.DrawTexture(new Rect(myScreenPosition.x - 100, myScreenPosition.y - 240, 263, 163), texture, Scale$$anonymous$$ode.ScaleToFit, true);        
         }
 
     }

Now that is worked pretty fine, thank you.

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

21 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

Related Questions

Distribute terrain in zones 3 Answers

Can I create a sprite at runtime? 3 Answers

WWW loading not working on Windows, working on Mac 1 Answer

asset bundle works fine on url1 but doesn't on url2? 0 Answers

Network class vs php for authoritative actions? 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