- Home /
Show gameobject as part of UI
I've recently asked a question, on how to instantiate a sprite. I got the answer, that I need a Sprite Renderer on a GameObject and I should rather instantiate that. So I created an empty GameObject and attached a Sprite Renderer to it, then made it a prefab and kept on going. The problem now is, that when I test the Sprite, the Image works like it should in the Scene-view, but the Sprite is rendered as a 3D Object inside the GameView, and not as part of the UI.
Why would you want to do that might I ask? Just set the camera view to orthographic and it's 2D
I've got a basic 3D game, in which I need a UI. The UI consists of some texts and 2 Sprites, which I want to instantiate. So I can't really change the camera settings, since the game is supposed to be 3D. I just need a way to get the Empty GameObject to be shown in the UI.
Answer by ilham_fzn28 · Feb 14, 2018 at 09:46 AM
On the Instantiate function, there is one more parameter to set your instantiated object parent... Check here : https://docs.unity3d.com/ScriptReference/Object.Instantiate.html . And if you want to create an object UI, you should create it with UI Component... Sprite Rendered is not for UI, so if you want to check what component UI is, go to here : https://unity3d.com/learn/tutorials/s/user-interface-ui These tutorial tell you everything about UI... . Note : UI component must always inside the Canvas...