Gizmos.DrawWireCube(new Vector3(0,0,center), new Vector3(camera.orthographicSize*2*camera.aspect, camera.orthographicSize*2, spread)) Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one) įloat spread = camera.farClipPlane - camera.nearClipPlane įloat center = (camera.farClipPlane + camera.nearClipPlane)*0.5f Public Constraint constraint = Constraint.Portrait Ĭamera.orthographicSize = 1f / camera.aspect * UnitsSize / 2f Ĭamera.orthographicSize = UnitsSize / 2f Public float UnitsSize = 1 // size of your scene in unity units Public class ViewportHandler : MonoBehaviour OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, IN NO EVENT SHALL THEĪUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,įITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR The above copyright notice and this permission notice shall be included inĪll copies or substantial portions of the Software. To use, copy, modify, merge, publish, distribute, sublicense, and/or sellĬopies of the Software, and to permit persons to whom the Software isįurnished to do so, subject to the following conditions: In the Software without restriction, including without limitation the rights Of this software and associated documentation files (the "Software"), to deal ![]() Permission is hereby granted, free of charge, to any person obtaining a copy ![]() What you want is to constrain the camera viewport on portrait or landscape(depending on your needs), by computing camera.orthographicSize property, so you can build your 2d scene regardless of aspect ratio and resolution: // Attach this script on your main ortohgraphic camera:
0 Comments
Leave a Reply. |