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 Natasa · May 10, 2015 at 06:46 PM · gameobjectdisplayworldspacescreenspacepixels

Scale Gameobject with defined size in pixels

I'm still new with Unity (5.0.0f4 Personal).

I'm working on a simple memory game, three levels with different number of cards to find pairs. I want my game to display cards on different screen sizes of Android devices. But as I think, I don't understand enough screenspace and worldspace.

I calculated two positions, one for x and second for y coordinate for each card I want to display. But I have no idea, how to scale my card to the calculated card size (pixels)...

Vector3 pozicijaKarta = Camera.main.ScreenToWorldPoint(new Vector3(xpozicija, ypozicija, 10));

Any help will be appreciated!

alt text

capture.jpg (111.1 kB)
Comment
Add comment · Show 6
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 Cherno · May 10, 2015 at 08:22 PM 0
Share

You have access to Screen.width and Screen.height, which give you the current height and width of the game screen/window in pixels. You can use this information to scale any elements on the screen. Are the cards actual GameObjects with a Renderer, or are they just Textures drawn on screen?

avatar image Natasa · May 10, 2015 at 10:19 PM 0
Share

Cards are GameObjects. The Cards I created in Blender and I'm using 3D animation for open/close on click.

avatar image Cherno · May 10, 2015 at 11:17 PM 0
Share

Ok, in that case, it's gonna be very complicated. Theoretically, you could take the Renderer.bounds of a card object, take the eight corner points coordinates, convert those into Screen space, and compare those to the Screen.width and Screen.height to get an idea of their relative scale.

avatar image Natasa · May 22, 2015 at 03:29 PM 0
Share

Yes, it's complicated.. I know how to get corner points (Vector3) and convert them to Screenspace(px). But how can I calculate the maximum scale of my cards to fit in any size of screen on devices? Is there any connection between Screenspace and Worldspace in Unity?

avatar image Cherno · May 22, 2015 at 11:16 PM 1
Share

You can get the ScreenSpace coordinates of a cube's corner points. You also have the total Screen.width and Screen.height. This is all you need to deter$$anonymous$$e how many cubed will fit at their current size. Take the SP coordinate of one of the two right corners points and subract from it the SP coordinate of one of the two left corner points. This is the width of the cube in ScreenSpace pixels. Divide the Screen.width by the cube width and you know how many times the cube will fit horizontally at it's current size. This can also be done with ViewportSpace, where you use 1.0 ins$$anonymous$$d of Screen.width.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Pangamini · May 11, 2015 at 07:58 AM

The easiest way for you would be to use uGUI classes, Canvas and Rect Transform. These will do most of the dirty work for you. Just read the GUI Docs. You are not fixed to canvas renderers, so if you want to use 3D cubes, you still can. Take a look at layout components, they will provide super easy to use tools for what you need.

Comment
Add comment · Show 1 · 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 Natasa · May 22, 2015 at 03:19 PM 0
Share

If I understand the concept of Canvas and Rect Transform, then I can't use them. $$anonymous$$y cards are prefab, created and displayed with Instantiate. Canvas and Rect Transform are great for menus. Or maybe I'm wrong?

avatar image
0

Answer by Natasa · Oct 20, 2015 at 10:04 PM

@Cherno I did just like you said. Many thanks for your help! I had some troubles to find out how to get all 4 cube's corner points. If anyone else will have the same problem, I'll write simple instructions...

top left: min_x, max_y top right: max_x, min_y bottom left: min_x, max_y bottom right: max_y, min_y

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Convert world to screenspace for screenshot of particular object 1 Answer

how to get the most right point or left point atc of object as visual on the screen in 3d project? 0 Answers

Monitor or screen output onto a game object. 1 Answer

text display on touch 1 Answer

How to display the gameobjects of a worldspace canvas in front of gameobjects of screen space overlay canvas? 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