How would I go about rendering a game object (3d model in this case) but only if it is in a certain area of the screen (eg middle 30% of screen).
I want to have something render only if its center is withing the bounds of a the screen middle lets say my screen is 480pixels height (example but need it to be resolution independent) and i want it to show only if its position is between(screen height) of 168 and 312.
Thanks for any help.
You want to use 2 cameras.
- Set each camera’s clear flag to depth only
- set each camera’s depth(the higher depths draw on top)
- Create a new layer
- set the gameObject’s layer to the newly created layer
- change the “clipping” camera’s Cull Mask to only your new layer
- Set the other camera’s Cull Mask to everything but your new layer
- Adjust the normalized view port rect to the appropriate size
Your gameobject will only be visible when inside the view rect.
Have a look at
Camera.WorldToScreenPoint here :
the sample code pretty much explains everything
I Hope this helps!