- Home /
Changing Normalized Viewport Rect Coords at Runtime?
Is it possible to change a camera's normalized viewport coords at runtime?
Answer by Mike 3 · Dec 25, 2010 at 06:03 AM
Yup, use Camera.rect
e.g.
Camera.main.rect = new Rect(0,0,1,1); //set the camera back to taking up the full screen
I'm curious as to why I'm able to adjust the camera.rect.height value, but camera.rect.top is ready only.
read only`s need to have their value cached in an equivalent type. the read only value can the n be passed to the cache to manipulate it in some way. once the manipulation to the value is achieved, you can pass it back through the specified matching type. The same issues arise when trying to do this with any read only type in C# not only Unity3D. I`m willing to hedge a bet that you may have already come across this with anything based around altering something like a gameObject`s transform.position transform.position.x`s, for example, position is locked inside the read only type, we cant directly access it, so we have to cache "transform.position" to something like a vector3(or exactly like one, if you like, like). Once we have this value in the Vector3 typed cache you can obviously manipulate the positional values of each vector axis (x,y,z) as you are in control of that Vector. Once you have changed the single value you wanted to change this can then be passed back to the read only type in the same way you cached to the vector in the first place , just reversed. Anyway, no doubt I have brought further confusions using the Transform class as an example/metaphor, though the answer is still valid to your Camera class troubles. What $$anonymous$$ike 3 has written , does indeed and very simply solve your problem...as whyy would you fell more comfortable controlling the top alone over the entire rectangle?( ...just a thought...)
Take care bud and thanks for reading, hope something in there makes some sense. gruffy
Your answer
Follow this Question
Related Questions
How to resize a camera's orthoSize for an object to fit inside its rect viewport? 1 Answer
Camera position in Viewport coordinates 2 Answers
Move an object in world space on the viewport 0 Answers
How to know where camera extents are inside editor? 1 Answer
is it possible to set the view port rect at both ends 1 Answer