Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Center an object in Ortographic view

$
0
0
Hi, I have a complicated problem to solve: I have a rectangular GameObject (a wall) that have to be centered inside an ortographic camera. It has to be zoomed in as much as possible but at the same time i need that he has a fixed padding from the sides of the screen (for example, from the wall at the edge of the screen there must always be a minimum of 60 px). The width of the wall is variable and therefore the size parameter must be recalculated each time after the wall resizing. I found this code to resize the wall height in order to fit the entire screen: Camera.main.orthographicSize = target.renderer.bounds.extents.y; I tried to modify the code as follows but did not get a proper solution: public void changeOrthoSize () { GameObject wall = GameObject.FindGameObjectWithTag("Wall"); float orthoSize; float rulerPadding = 60; if (wall.renderer.bounds.extents.x > wall.renderer.bounds.extents.y){ // divide by 2 the x size to catch the y size if (wall.renderer.bounds.extents.x * 0.6f >= wall.renderer.bounds.extents.y){ orthoSize = wall.renderer.bounds.extents.x * 0.6f + rulerPadding * 0.5f; } else { orthoSize = wall.renderer.bounds.extents.y + rulerPadding; } } else { orthoSize = wall.renderer.bounds.extents.y + rulerPadding; } Camera.main.orthographicSize = orthoSize; } Anyone have any suggestions for this problem? Thanks in advance

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>