How to render gameobject only if in certain portion of view rect?

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.

  1. Set each camera’s clear flag to depth only
  2. set each camera’s depth(the higher depths draw on top)
  3. Create a new layer
  4. set the gameObject’s layer to the newly created layer
  5. change the “clipping” camera’s Cull Mask to only your new layer
  6. Set the other camera’s Cull Mask to everything but your new layer
  7. 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!