- Home /
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?
What is a clear object? Is it a UI in world space or on screen? You would have to elaborate a little what you want to get.
As i understand, he might want to see some text in 3D space as if it was displayed on some sort of glass display. So the text is behind the glass, but it's "projected" on it... sort of like the display in the library of the movie The Time $$anonymous$$achine.. but i might be wrong :)
Answer by KdRWaylander · Jun 29, 2015 at 11:27 AM
Hi,
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 !
http://docs.unity3d.com/ScriptReference/GameObject-layer.html
If toggling the object would be an option, it'd be much clearer to disable/enable object from camera render callbacks ins$$anonymous$$d of changing object layer.
Answer by Pangamini · Jun 29, 2015 at 11:53 AM
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).
Do you have any links that would better explain for example a tutorial because i didnt quite understand what you said
BTW I just realized all of this can be done without a line of code, just use built-in Canvas to render your text and use $$anonymous$$ask to clip out the text to only be seen in your window/object
Your answer

Follow this Question
Related Questions
UI Text compression on android 1 Answer
Render Debug.Log as UI Text 2 Answers
What's your equivalent of old GUIStyle ? 0 Answers
Canvas is flipping, 2D game 0 Answers