|
I have some objects in my game that are intended to be HUD items. When I zoom out with an orthographic camera by changing the orthographicSize property, I don't want my HUD's size to change. So I thought I'd increase the scale of my HUD as I zoomed out. Is there some magic number I can use to set the scale based on the current orthographicSize property?
(comments are locked)
|
|
Hm? As the documentation page states, the screen height is just camera.orthographicSize*2 world coordinates, it doesn't get much simpler than that. Also, that's not even relevant, since you can use relative scaling. So store your initial orthographicSize size somewhere, and then scale your HUD with Note unless you also want to shift positions around (which of course also change), keep all your individual HUD objects in an empty GameObject attached to the camera, make sure it has no local transformations except a z position that's larger than your nearClip value, and only scale this object. All children objects will then seem to stay in place, when changing the size.
(comments are locked)
|

I dont know about the magic number, but you can use multiple cameras and leave the scale alone. just make your HUD camera a child of your main camera. use the culling masks of your hud camera to only show stuff on the HUD layer and the main camera to show everything but the hud. also make sure that the depth of your hud camera is bigger than the main cameras. hope that helps
I had no idea multiple cameras could be used to create a single view. This sounds like a good solution but I've may have run into an issue.
I've added a 2nd camera and made it a child of the main one. I created a layer called HUD and the 2nd camera only has the HUD layer checked, while the 1st has everything but HUD checked. The main camera's depth is -2 and the HUD camera's depth is -1. When I go into my game, I can only see my HUD. What's odd is I can see objects in the main camera's preview while in the edit mode.
I've also tried not having any culling on the main camera and tell it show show everything. But I still only see the HUD layer.
edit: Ok, I found that I needed to set the Clear Flags in the HUD camera to depth only. This works perfect! Thanks!
Set the HUD camera's "clear flags" to "Don't Clear".
Note that using two cameras is more expensive than using ony one camera.
I'm using the camera in my game like this. The relative scales are: