Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
4
Question by moghes · Apr 24, 2013 at 01:55 PM · cameratransform.positionscreenspacepixelinset

scale plane to fit to screen size

Hello everyone,

I have an orthographic camera of size 100, and I have a plane that I want to fit/scale according to the screen size. To be more clear, I want the functionality of a guiTexture on a plane/mesh.

In the case of a guitexture, I would have set transform.postion = vector3(0,0,0) and play with the values of pixelInset like:

 myGuiTexture.pixelInset = new Rect(0,0,Screen.currentResolution.width,Screen.currentResolution.height);

So how to achieve something like this with transform.position or any other method to do this with 3D object. I want this since I am using tk2d and I want my sprite animation to fill the whole screen.

Thanks,

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

1 Reply

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

Answer by robertbu · Apr 24, 2013 at 03:06 PM

Since you are using an orthographic camera, from the reference:

[OrthographicSize] is half of the vertical size of the viewing volume. Horizontal viewing size varies depending on viewport's aspect ratio.

So you will set the vertical size of your plane to twice the orthographic size and then scale the horizontal based on the ratio of Screen.width / Screen.height.

Comment
Add comment · Show 10 · 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 moghes · Apr 24, 2013 at 04:17 PM 0
Share

@robertbu thank you for your support.. Here's my script:

 transform.localScale = new Vector3(cam.orthographicSize/2 * (Screen.width/Screen.height),cam.orthographicSize/2,0f);

but its not fitting perfectly, the width is smaller than screen width (there are narrow vertical columns on both sides), and the height is more than Screen.height.. what might be my fault?

avatar image robertbu · Apr 24, 2013 at 08:35 PM 2
Share

Your calculations are wrong. Attach this to a standard cube to verify the code:

 function Start () {
 
     var height = Camera.main.orthographicSize * 2.0;
     var width = height * Screen.width / Screen.height;
     transform.localScale = Vector3(width, height, 0.1);
 }

Now you need to verify some some things about the plane you are using. First how big is it? The standard plane in unity is 10x10 when scaled to (1,1,1). And what is the orientation? For the standard plane you will need to modify the Z parameter rather than the y parameter. To get a plane the right size and orientation you can use the CreatePlane script.

avatar image moghes · Apr 25, 2013 at 06:39 AM 0
Share

@robertbu thank you again, but I am using 2DToolkit, and I have a sprite , how to know how big it is? Its scale is (1,1,1) ..

avatar image robertbu · Apr 25, 2013 at 01:22 PM 0
Share

I don't know 2DToolkit, so I don't know how they size things. Do they base size and/or aspect based on the texture, or do you enter the size as part of a script? As a starting point, take a sprite with a square texture and compare it to a thin cube.

avatar image AlexeyGapon · Jul 18, 2014 at 09:07 PM 0
Share

This Script is not working for me the plane is musch bigger then the screen.

avatar image icaropablo2 AlexeyGapon · Nov 24, 2015 at 10:09 AM 0
Share

Try this c# code

float height = (float)Camera.main.orthographicSize 2.0f; float width = height Screen.width / Screen.height; transform.localScale = new Vector3(width/10, 1.0f, height/10);

Show more comments

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

14 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

Related Questions

Object not centering with screen.width/2 0 Answers

Unity Camera and transform? 1 Answer

Spawn objects at bottom of screen / camera 2 Answers

Multiple Targets Camera 1 Answer

Second UI camera only works when I refresh Clear Flags setting 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