- Home /
2D UI in 3D space
Hey guys I was looking at "Deus Ex: Manking Divided", and it gave me the idea for UI in my game. As you can see from this (1:00 for example) video they have some 2D images attached on the 3D objects (it looks like that to the player), when you move your camera in the game they stay at the same place. How could I recreate that effect in Unity? I was thinking that it's maybe an Image attached to a world space canvas and it has a script on it to face the camera all the time but that's not the case.
Answer by Vicarian · Aug 16, 2018 at 02:45 PM
I don't think it's actually world space at all. I think what's happening is that a raycast is getting performed, an object Adam can interact with is getting found (in this case a window he can open), and an equivalent WorldToScreenPoint calculation is getting performed to place the leader line as well as the image. All the UI elements are still screen space overlay.
Answer by Bartson · Aug 16, 2018 at 12:49 PM
Just use SpriteRenderer component in Empty GameObject. For texts use TextMesh.
If I use SpriteRenderer it gets affected by all of the lightning on the scene, it doesn't look like the UI from the video. UI from the video looks like it's a Image component on the canvas, unaffected by the light in the scene. Also the UI doesn't seem to get bigger as the camera gets closer to it.
Answer by Sazails · Aug 16, 2018 at 01:02 PM
Hi, To use this I would recommend a quad with a streched out canvas applied to it in worldspace mode. The "look at" function should actually work for this too, make sure it is attached to the quad holding the canvas. Then you could use Vector3.Distance to get the distance between player and the UI and decide how the scaling would work depending of how close or far you might be to the object (quad).
Hope you understand :)
Your answer
Follow this Question
Related Questions
How do I make UI elements go behind my 2D game objects? 1 Answer
Canvas Screen Space Issue 1 Answer
Unity 2D not rendering images in Canvas 1 Answer