I come from a background of coding flash applications for many years and I'm finding it hard to do things that were previously very simple with 2d pixel based space in Unity. I was hoping for some input on how one would go about doing them in 3d.
The lack of width and height relative to the screen is the main thing I am struggling to come to terms with. For example, in flash I could make an object fill the screen by simply doing:
Or I could center an object by doing:-
I have worked out that localeScale and localePosition can be used for some things. If someone could post how they would commonly perform these tasks in Unity, along with any other examples, it would help me a lot.
asked Dec 05 '10 at 09:47 PM
I use something like this to achieve what you are trying to do:
public Camera cam;
Now, if your object has a scale of (1, 1, 1) by default you can just use viewWidth and viewHeight to adjust it's scale to fill the screen.
obj.transform.localScale = new Vector3(viewWidth, viewHeight, 1);
Hope that helps.
answered Jun 23 '12 at 11:52 AM
(NOTE: Camera.main.pixelHeight is the same as Screen.height, if your camera fills the whole screen (as opposed to for example a picture-in-picture camera)
EDIT before even posting: I just realized that @DelStrega revived this ancient question from 2010, which is generally not a good idea. But that was when I finished typing, so I'll post my answer anyway.