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!

What is the reason of you using perspective camera setup?

There are 3 simple ways:

  1. Use Unity 2D Tools (ex: Sprite).
  2. Use ortographic camera
  3. Use new Unity GUI.

Do you need 3d graphics?

I made 3D animation for cards to open and close when you click on them…

The script attached works for flat quads parallel to the camera projection plane.

Basic idea is to get bounding box from mesh filter, transform it into screen space. Now you know current pixel size of the object.

You have target pixel size. So just multiply current scale by target size / current size. That’s all

2105252–137984–PixelScaler.cs (911 Bytes)

Thank you very much! I’ll let you know if it works.