Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
6
Question by BhargavChauhan · Sep 30, 2016 at 09:38 AM · canvasimagescreen size

Set the UI Image to fit Screen Size

I want to scale or set the height,width to fit screen size. I can do it by inspector using anchor preset,Same thing I want to do it by script.

My Canvas setting is Renderer Mode :- Screen Space - Camera , UI Scale Mode :- Scale with Screen Size.

alt text

alt text

2.jpg (191.3 kB)
1.jpg (42.0 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

3 Replies

· Add your reply
  • Sort: 
avatar image
25

Answer by Mukabr · Sep 30, 2016 at 04:52 PM

On RectTransform inspector UI, press on that "middle/center" graph and than, while holding Alt key, press on "Stretch/Stretch" alt text

Using code, you can control the anchors with:

http://docs.unity3d.com/ScriptReference/RectTransform-anchorMin.html http://docs.unity3d.com/ScriptReference/RectTransform-anchorMax.html http://docs.unity3d.com/ScriptReference/RectTransform-pivot.html

 public RectTransform panelRectTransform;
  
  // Something like this.
  void Start()
  {
     panelRectTransform.anchorMin = new Vector2(1, 0);
     panelRectTransform.anchorMax = new Vector2(0, 1);
     panelRectTransform.pivot = new Vector2(0.5f, 0.5f);
  }



fullscreen.png (6.8 kB)
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 SkyGolem · Nov 24, 2018 at 04:26 PM 0
Share

That technically works but it f*cks up the aspect ratio

avatar image Mukabr SkyGolem · May 02, 2019 at 09:47 AM 1
Share

If you mean the Image got distorted, all you have to do is check the Preserv Aspect box.

avatar image emredesu · Sep 19, 2021 at 06:33 PM 0
Share

Do note that your canvas' UI scale mode needs to be set to "Scale With Screen Size" and Screen Match Mode needs to be set to "Shrink" for this to work.

avatar image
1

Answer by Muchmu · Jan 14, 2021 at 06:04 PM

solved ( i think ) it worked for me at least but i was working with a render texture but i had streching problems and this solved it so it should work for other images ( I did use a raw image on the canvas though so that might have something to do with it )

You need toalt text

alt text

that worked for me


1.png (118.2 kB)
screenshot-42.png (21.0 kB)
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 SaurabhStudio · Sep 30, 2016 at 04:54 PM

Set height,width to the size of canvas height,width. And set anchor point to the corner of canvas.

And for more details check this. https://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html

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

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

12 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

Related Questions

Need Mask Shader . 0 Answers

How to have TextMesh Pro text appear above image? 0 Answers

what will happen if i use SpriteRenderer component in a Canvas Instead of Image component ? 0 Answers

Rare players have serious issues with disappearing or distorted images and sprites 0 Answers

Convert UI element to world position 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