Make a text visable only through an object

Is it possable to make a UI text only able to be seen through a clear object and when it moves away you cant see the text any more?

If toggling of object on and off is not an option (eg. you want to see part of the text and part occluded) you will need to play with shaders a bit. One option would be to play with stencil a bit, set it to some value where your “window” is, and then render the text with stencil check (so it’s culled everywhere except for the “window”). If your window itself is a transparent object, you will need to render the text first (or last, as a result of transparent object depth sorting). In this case you have to render the window stencil separately as an opaque object, then render text and window as transparent objects (with text still doing the stencil check).


What you can do is set a specific layer to your object, like “HiddenLayer”, and make your camera not to see this particular layer. Whenever you have your object you want to see through in position or whatever event/trigger, you can change the layer of the text (e.g. set it back to default layer) so you will see it. When the object is out of position, you set back the text layer to the layer the camera(s) can’t see !